Lillapojkenpåön Posted May 10, 2020 Share Posted May 10, 2020 (edited) What is temp7's purpose when bankswitching? .L08 ; goto _bank2 bank2 sta temp7 lda #>(._bank2-1) pha lda #<(._bank2-1) pha lda temp7 pha txa pha ldx #2 jmp BS_jsr BS_jsr lda bankswitch_hotspot-1,x pla tax pla rts It looks to me like it's just used to push what's currently in the accumulator to the stack, and that you also push x to the stack, is that just so you can continue your code in another bank? There's no way to ldx or lda (without also assigning it to a variable) in bB, and even if there where, wouldn't it be faster to just sta temp1 stx temp2 and load them after the bankswitching lda temp1 ldx temp2 If I don't need to keep what's in a and x would this work lda #>(._bank2-1) pha lda #<(._bank2-1) pha ldx #2 lda bankswitch_hotspot-1,x rts Just tried it and I got error: Unknown Mnemonic 'bankswitch_hotspot-1,x'. Is bankswitch_hotspot a table? I can't find it anywhere. Edited May 10, 2020 by Lillapojkenpåön Quote Link to comment Share on other sites More sharing options...
Lillapojkenpåön Posted May 10, 2020 Author Share Posted May 10, 2020 (edited) Woops answered here But I still need to know how to put the hotspots in a table or something? hotspots $FFF6 $FFF7 $FFF8 $FFF9 $FFFA $FFFB I tried this lda $fff6,x and -1 to but didn't work Edited May 10, 2020 by Lillapojkenpåön Quote Link to comment Share on other sites More sharing options...
+Karl G Posted May 10, 2020 Share Posted May 10, 2020 The specific hotspot for bankswitching depends on the size of your project, so using the bankswitch_hotspot constant instead of a hardcoded value is a good idea. I don't know why the stack is used to preserve register values instead of temp variables; maybe @RevEng can answer that part. Hotspots are not in a table. They are addresses that trigger a bankswitch in the hardware if they are accessed (read from or written to). If you just do a "lda bankswitch_hotspot" the code would switch to the first bank. Each address following bankswitch_hotspot would switch to the following bank. The X register contains the bank you are switching to. bB starts counting banks at 1 instead of 0, so that's why it uses "lda bankswitch_hotspot-1,x". 1 Quote Link to comment Share on other sites More sharing options...
bogax Posted May 10, 2020 Share Posted May 10, 2020 it appears to work with just a little trickery set romsize 16k set optimization inlinerand const targetlo = <(.dloop-1) const targethi = >(.dloop-1) def gt_bank = callmacro bsm macro bsm asm lda #{2} pha lda #{1} pha ldx {3} lda bankswitch_hotspot-1,x jmp BS_jsr+6 end end q = $55 gt_bank targetlo targethi 2 bank 2 a = a dloop c = c + 1 if !c & $7F then q = q ^ $FF : COLUBK = q if e && joy0fire then q = q + 4 : COLUBK = q if joy0fire then e = 0 else e = 1 drawscreen goto dloop bank 3 bank 4 Quote Link to comment Share on other sites More sharing options...
RevEng Posted May 10, 2020 Share Posted May 10, 2020 The intent of temp7 is indeed to save save A. As to the question of why other temp variables weren't used, I believe the intent was to eventually bankswitch-enable certain bB functions that are already using the temps. e.g. the div_mul libraries. 1 Quote Link to comment Share on other sites More sharing options...
bogax Posted May 10, 2020 Share Posted May 10, 2020 if I do this def gt_bank = callmacro bsm macro bsm asm lda #>(.{1}-1) pha lda #<(.{1}-1) pha ldx {2} lda bankswitch_hotspot-1,x jmp BS_jsr+6 end end gt_bank dloop 2 it complains about uresolved symbol 1.dloop I don't know where that comes from it seems to produce correct code but won't assemble 90 1004 .L08 ; gt_bank dloop 2 91 1004 0 1004 bsm dloop, #2, 1 1004 2 1004 .L06 3 1004 4 1004 a9 ff lda #>(.dloop-1) 5 1006 6 1006 48 pha 7 1007 8 1007 a9 ff lda #<(.dloop-1) 9 1009 10 1009 48 pha 11 100a 12 100a a2 02 ldx #2 13 100c 14 100c bd f5 1f lda bankswitch_hotspot-1,x 15 100f 16 100f 4c f1 ff jmp BS_jsr+6 copy and paste errror in the previous code (although it seems to work) should have been macro bsm asm lda {2} pha lda {1} pha ldx {3} lda bankswitch_hotspot-1,x jmp BS_jsr+6 end end Quote Link to comment Share on other sites More sharing options...
RevEng Posted May 10, 2020 Share Posted May 10, 2020 17 minutes ago, bogax said: It complains about uresolved symbol 1.dloop I don't know where that comes from it seems to produce correct code but won't assemble Dasm considers dot symbols to be limited in scope. I'm pretty sure that limits the dasm in-macro access to bB labels. 1 Quote Link to comment Share on other sites More sharing options...
bogax Posted May 10, 2020 Share Posted May 10, 2020 18 minutes ago, RevEng said: Dasm considers dot symbols to be limited in scope. I'm pretty sure that limits the dasm in-macro access to bB labels. well in that case set romsize 16k set optimization inlinerand set optimization noinlinedata def gt_bank = callmacro bsm macro bsm asm lda #>({1}-1) pha lda #<({1}-1) pha ldx {2} lda bankswitch_hotspot-1,x jmp BS_jsr+6 end end q = $55 gt_bank dloop 2 bank 2 a = a data dloop end dloop c = c + 1 if !c & $7F then q = q ^ $FF : COLUBK = q if e && joy0fire then q = q + 4 : COLUBK = q if joy0fire then e = 0 else e = 1 drawscreen goto dloop bank 3 bank 4 (yes , it works) 1 Quote Link to comment Share on other sites More sharing options...
Lillapojkenpåön Posted May 11, 2020 Author Share Posted May 11, 2020 IObBCC.. I've read several times that macros are slow, so I guess when using it you don't input a copy of that code with the parameters you give? Or if you do does that happen when it turns into machine language? 18 hours ago, Karl G said: The specific hotspot for bankswitching depends on the size of your project, so using the bankswitch_hotspot constant instead of a hardcoded value is a good idea. Hotspots are not in a table. They are addresses that trigger a bankswitch in the hardware if they are accessed (read from or written to). bB starts counting banks at 1 instead of 0, so that's why it uses "lda bankswitch_hotspot-1,x". I couldn't use the bankswitch_hotspot constant before without getting an error, now I can for some reason. maybe the problem is that I'm trying to jump to another bank and return to the old bank again, on gosub with bankswitch, which bB doesn't support, this is the first part asm lda #>(._ongosub_return_-1) PHA lda #<(._ongosub_return_-1) PHA LDX bankNumber ; 4 in this case LDA _jumptablehi_,x PHA LDA _jumptablelo_,x PHA lda bankswitch_hotspot-1,x rts _jumptablehi_ .byte #0 .byte #0 .byte #0 .byte >(._bank3data-1) .byte >(._bank4data-1) .byte >(._bank5data-1) .byte >(._bank6data-1) _jumptablelo_ .byte #0 .byte #0 .byte #0 .byte <(._bank3data-1) .byte <(._bank4data-1) .byte <(._bank5data-1) .byte <(._bank6data-1) end _ongosub_return_ I probably need to make a custom return otherbank code also, what do I change? getting rid of the a and x stuff didn't work asm pha ;push a to stack txa pha ; push x to stack tsx ; Transfer Stack ptr to X if bankswitch != 64 lda 4,x ; get high byte of return address rol rol rol rol and #bs_mask ;1 3 or 7 for F8/F6/F4 tax inx else lda 4,x ; get high byte of return address tay ora #$10 ; change our bank nibble into a valid rom mirror sta 4,x tya lsr lsr lsr lsr tax inx endif lda bankswitch_hotspot-1,x pla tax ; *** restore X pla ; *** restore A rts ; *** RTS will "return" to the address we pushed onto the stack earlier end Quote Link to comment Share on other sites More sharing options...
Lillapojkenpåön Posted May 11, 2020 Author Share Posted May 11, 2020 (edited) If someone can get this to work, I would be happy you gosub to bank 4 by pressing joy0fire, it should change bgcolor to blue bankswitch2.bas and is the jmp BS_jsr+6 in bogax code because you have to do the rts at that address? Edited May 11, 2020 by Lillapojkenpåön Quote Link to comment Share on other sites More sharing options...
bogax Posted May 11, 2020 Share Posted May 11, 2020 it doesn't work as advertised the BS_jsr+6 comes after the bank switch and so never executes it just so happens that the bank switch ends up in the dloop I haven't figured out how to fix it Quote Link to comment Share on other sites More sharing options...
bogax Posted May 11, 2020 Share Posted May 11, 2020 if you're just trying to compute your target you can set something up with on gosub and on goto put gotos for each bank (or each possible target bank) in each bank tha you might be coming from and a dispatch on goto for each possible target in the bank in other words on gosub to a goto bank (in the current bank) that goes to an on goto in the target bank that selects the routine you want in that bank Quote Link to comment Share on other sites More sharing options...
Lillapojkenpåön Posted May 11, 2020 Author Share Posted May 11, 2020 I did that, but think I did on gosub to gosub to another bank, so I could return, then I just merged the codes in assembly sta temp7 lda #>(._ongosub_return_-1) PHA lda #<(._ongosub_return_-1) PHA LDX bankNumber LDA _jumptablehi_,x PHA LDA _jumptablelo_,x PHA lda temp7 pha txa pha ldx bankNumber jmp BS_jsr this works perfectly with a regular return otherbank So I'm not trying to get it to work, I'm trying to optimize it by removing as much excess as possible and hopefully get a little bit closer to understanding bankswitching in the process. I don't need to save a and x, but BS_jsr and BS_return (that falls into BS_JSR) tries to pull them from the stack, I think that's what the problem is. Quote Link to comment Share on other sites More sharing options...
bogax Posted May 11, 2020 Share Posted May 11, 2020 this works, but it's getting messy the to_bank macro just loads the target address to the stack you then have to goto the bank switch code at the beginning of the bank the location of the bank switch code has to be the same in all banks and the beginning of the bank seemed simplest since you have to jump around it in the first bank there's padding in the rest (in place of the jump/goto) set romsize 16k set optimization inlinerand set optimization noinlinedata def to_bank = callmacro bsm def go_to = callmacro gtom macro bsm asm lda #>({2}-1) pha lda #<({2}-1) pha ldx {1} end end macro gtom asm jmp {1} end end def bswitch = callmacro bswm macro bswm asm nop nop nop lda bankswitch_hotspot-1,x rts end end goto skip_BS_code bs1 asm lda bankswitch_hotspot-1,x rts end skip_BS_code gosub init to_bank 2 dloop goto bs1 init q = $55 COLUBK = q COLUPF = $33 return thisbank bank 2 bs2 bswitch data dloop end c = c + 1 if !c & $7F then q = q ^ $FF : COLUBK = q if e && joy0fire then q = q + 4 : COLUBK = q if joy0fire then e = 0 else e = 1 drawscreen go_to dloop bank 3 bank 4 1 Quote Link to comment Share on other sites More sharing options...
Lillapojkenpåön Posted May 11, 2020 Author Share Posted May 11, 2020 Aah, now I get it, ofcourse that code has to be in the same place in all banks ? Thanks, it doesn't support returning but I can add that. I'm also trying to save space and I got my previous code down to this lda #>(._ongosub_return2_-1) PHA lda #<(._ongosub_return2_-1) PHA LDX bankNumber LDA _jumptablehi_,x PHA LDA _jumptablelo_,x PHA pha pha jmp BS_jsr just two extra pushes to get the existing bs code to work and return, not shure it would be worth adding another slightly modified version to every bank just to get rid of the extra pushing and pulling, but I sure will try it. What the hell is a macro anyway? Quote Link to comment Share on other sites More sharing options...
bogax Posted May 12, 2020 Share Posted May 12, 2020 you're indexing your table with the bank number(?) in this case a macro is sort of like an inlined function Quote Link to comment Share on other sites More sharing options...
Lillapojkenpåön Posted May 12, 2020 Author Share Posted May 12, 2020 yup, it's just so I can read data from other banks with indirect y, so theres just one jump to each bank in the table, in the correct order Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.