From 69c610474214097b88afaef10272d3553eccb0fb Mon Sep 17 00:00:00 2001 From: Lucas Scharenbroich Date: Thu, 26 Aug 2021 16:12:08 -0500 Subject: [PATCH] Small initialization and jsr/jsl updates --- src/App.Main.s | 158 ++++++++++++++++------------------------- src/Core.s | 11 +++ src/Defs.s | 10 --- src/Graphics.s | 4 -- src/Render.s | 30 -------- src/TileMap.s | 28 ++++---- src/Timer.s | 3 + src/blitter/BG0.s | 121 +++++++++++++++---------------- src/blitter/Blitter.s | 1 - src/blitter/Horz.s | 1 - src/blitter/Template.s | 11 --- 11 files changed, 146 insertions(+), 232 deletions(-) diff --git a/src/App.Main.s b/src/App.Main.s index 2a191c1..06b4d7d 100644 --- a/src/App.Main.s +++ b/src/App.Main.s @@ -17,8 +17,8 @@ tiledata ext ; Feature flags -NO_INTERRUPTS equ 1 ; turn off for crossrunner debugging -NO_MUSIC equ 1 ; turn music + tool loading off +NO_INTERRUPTS equ 1 ; turn off for crossrunner debugging +NO_MUSIC equ 1 ; turn music + tool loading off ; Typical init phk @@ -30,24 +30,25 @@ NO_MUSIC equ 1 ; turn music + tool loadi jsl SetScreenMode ; Set up our level data - jsr BG0SetUp - jsr BG1SetUp +; jsr BG0SetUp +; jsr BG1SetUp ; Allocate room to load data - jsl AllocBank ; Alloc 64KB for Load/Unpack - sta BankLoad ; Store "Bank Pointer" +; jsl AllocBank ; Alloc 64KB for Load/Unpack +; sta BankLoad ; Store "Bank Pointer" - jsr MovePlayerToOrigin ; Put the player at the beginning of the map +; jsr MovePlayerToOrigin ; Put the player at the beginning of the map - lda #DIRTY_BIT_BG0_REFRESH ; Redraw all of the tiles on the next Render - ora #DIRTY_BIT_BG1_REFRESH - tsb DirtyBits +; lda #DIRTY_BIT_BG0_REFRESH ; Redraw all of the tiles on the next Render +; ora #DIRTY_BIT_BG1_REFRESH +; tsb DirtyBits +; lda #$FFFF jsl Render EvtLoop jsl ReadControl - and #$007F ; Ignore the buttons for now + and #$007F ; Ignore the buttons for now cmp #'q' bne :1 @@ -68,17 +69,17 @@ EvtLoop jsr DumpBanks bra EvtLoop -:3 cmp #'f' ; render a 'f'rame +:3 cmp #'f' ; render a 'f'rame bne :4 jsl Render bra EvtLoop -:4 cmp #'h' ; Show the 'h'eads up display +:4 cmp #'h' ; Show the 'h'eads up display bne :5 jsr DoHUP bra EvtLoop -:5 cmp #'1' ; User selects a new screen size +:5 cmp #'1' ; User selects a new screen size bcc :6 cmp #'9'+1 bcs :6 @@ -86,7 +87,7 @@ EvtLoop sbc #'1' tax jsl SetScreenMode - jsr MovePlayerToOrigin +; jsr MovePlayerToOrigin brl EvtLoop :6 cmp #'t' @@ -94,7 +95,7 @@ EvtLoop jsr DoTiles brl EvtLoop -:7 cmp #$15 ; left = $08, right = $15, up = $0B, down = $0A +:7 cmp #$15 ; left = $08, right = $15, up = $0B, down = $0A bne :8 lda #1 jsr MoveRight @@ -150,13 +151,13 @@ StartMusic pea #MusicFile _NTPLoadOneMusic - pea $0001 ; loop + pea $0001 ; loop _NTPPlayMusic rts ; Position the screen with the botom-left corner of the tilemap visible MovePlayerToOrigin - lda #0 ; Set the player's position + lda #0 ; Set the player's position jsl SetBG0XPos lda #0 jsl SetBG1XPos @@ -198,8 +199,8 @@ DoHUP ldx #{160-12*4} ldy #$7777 jsr DrawString - lda OneSecondCounter ; Number of elapsed seconds - ldx #{160-4*4} ; Render the word 4 charaters from right edge + lda OneSecondCounter ; Number of elapsed seconds + ldx #{160-4*4} ; Render the word 4 charaters from right edge jsr DrawWord lda #TicksStr @@ -220,7 +221,7 @@ DoTiles :column equ 3 :tile equ 5 - pea $0000 ; Allocate local variable space + pea $0000 ; Allocate local variable space pea $0000 pea $0000 @@ -250,7 +251,7 @@ DoTiles cmp #26 bcc :rowloop - pla ; restore the stack + pla ; restore the stack pla pla rts @@ -264,7 +265,7 @@ DoLoadBG1 ldx BankLoad lda #0 ldy BG1DataBank - jsr CopyBinToBG1 + jsl CopyBinToBG1 lda BankLoad ldx #BG1AltDataFile @@ -273,7 +274,7 @@ DoLoadBG1 ldx BankLoad lda #0 ldy BG1AltBank - jsr CopyBinToBG1 + jsl CopyBinToBG1 rts @@ -283,18 +284,18 @@ DoLoadFG ldx #FGName jsr LoadFile - ldx BankLoad ; Copy it into the code field + ldx BankLoad ; Copy it into the code field lda #0 - jsr CopyBinToField + jsl CopyBinToField rts ; Load a simple picture format onto the SHR screen DoLoadPic lda BankLoad - ldx #ImageName ; Load+Unpack Boot Picture - jsr LoadPicture ; X=Name, A=Bank to use for loading + ldx #ImageName ; Load+Unpack Boot Picture + jsr LoadPicture ; X=Name, A=Bank to use for loading - ldx BankLoad ; Copy it into the code field + ldx BankLoad ; Copy it into the code field lda #0 jsl CopyPicToField rts @@ -335,43 +336,43 @@ DefaultPalette dw $0E51,$0EDB,$0000,$068F,$0BF1,$00A0,$0EEE,$0777,$ ; Graphics helpers LoadPicture - jsr LoadFile ; X=Nom Image, A=Banc de chargement XX/00 + jsr LoadFile ; X=Nom Image, A=Banc de chargement XX/00 bcc :loadOK rts :loadOK - jsr UnpackPicture ; A=Packed Size + jsr UnpackPicture ; A=Packed Size rts -UnpackPicture sta UP_PackedSize ; Size of Packed Data - lda #$8000 ; Size of output Data Buffer +UnpackPicture sta UP_PackedSize ; Size of Packed Data + lda #$8000 ; Size of output Data Buffer sta UP_UnPackedSize - lda BankLoad ; Banc de chargement / Decompression - sta UP_Packed+1 ; Packed Data + lda BankLoad ; Banc de chargement / Decompression + sta UP_Packed+1 ; Packed Data clc adc #$0080 - stz UP_UnPacked ; On remet a zero car modifie par l'appel + stz UP_UnPacked ; On remet a zero car modifie par l'appel stz UP_UnPacked+2 - sta UP_UnPacked+1 ; Unpacked Data buffer + sta UP_UnPacked+1 ; Unpacked Data buffer - PushWord #0 ; Space for Result : Number of bytes unpacked - PushLong UP_Packed ; Pointer to buffer containing the packed data - PushWord UP_PackedSize ; Size of the Packed Data - PushLong #UP_UnPacked ; Pointer to Pointer to unpacked buffer - PushLong #UP_UnPackedSize ; Pointer to a Word containing size of unpacked data + PushWord #0 ; Space for Result : Number of bytes unpacked + PushLong UP_Packed ; Pointer to buffer containing the packed data + PushWord UP_PackedSize ; Size of the Packed Data + PushLong #UP_UnPacked ; Pointer to Pointer to unpacked buffer + PushLong #UP_UnPackedSize ; Pointer to a Word containing size of unpacked data _UnPackBytes - pla ; Number of byte unpacked + pla ; Number of byte unpacked rts -UP_Packed hex 00000000 ; Address of Packed Data -UP_PackedSize hex 0000 ; Size of Packed Data -UP_UnPacked hex 00000000 ; Address of Unpacked Data Buffer (modified) -UP_UnPackedSize hex 0000 ; Size of Unpacked Data Buffer (modified) +UP_Packed hex 00000000 ; Address of Packed Data +UP_PackedSize hex 0000 ; Size of Packed Data +UP_UnPacked hex 00000000 ; Address of Unpacked Data Buffer (modified) +UP_UnPackedSize hex 0000 ; Size of Unpacked Data Buffer (modified) ; Basic I/O function to load files LoadFile - stx openRec+4 ; X=File, A=Bank (high word) assumed zero for low + stx openRec+4 ; X=File, A=Bank (high word) assumed zero for low stz readRec+4 sta readRec+6 jsr ClearBankLoad @@ -393,7 +394,7 @@ LoadFile :closeFile _CloseGS closeRec clc - lda eofRec+4 ; File Size + lda eofRec+4 ; File Size rts :openReadErr jsr :closeFile @@ -426,22 +427,22 @@ BG1AltDataFile strl '1/bg1b.bin' ImageName strl '1/test.pic' FGName strl '1/fg1.bin' -openRec dw 2 ; pCount - ds 2 ; refNum - adrl FGName ; pathname +openRec dw 2 ; pCount + ds 2 ; refNum + adrl FGName ; pathname -eofRec dw 2 ; pCount - ds 2 ; refNum - ds 4 ; eof +eofRec dw 2 ; pCount + ds 2 ; refNum + ds 4 ; eof -readRec dw 4 ; pCount - ds 2 ; refNum - ds 4 ; dataBuffer - ds 4 ; requestCount - ds 4 ; transferCount +readRec dw 4 ; pCount + ds 2 ; refNum + ds 4 ; dataBuffer + ds 4 ; requestCount + ds 4 ; transferCount -closeRec dw 1 ; pCount - ds 2 ; refNum +closeRec dw 1 ; pCount + ds 2 ; refNum qtRec adrl $0000 da $00 @@ -453,36 +454,3 @@ qtRec adrl $0000 PUT App.TileMapBG0.s PUT App.TileMapBG1.s - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Core.s b/src/Core.s index 198c64a..f92f295 100644 --- a/src/Core.s +++ b/src/Core.s @@ -45,9 +45,15 @@ EngineStartUp ENT rtl EngineShutDown ENT + phb + phk + plb + jsr IntShutDown jsr SoundShutDown jsr ToolShutDown + + plb rtl ToolStartUp @@ -221,6 +227,11 @@ EngineReset stz TileMapPtr stz TileMapPtr+2 + stz BG1TileMapWidth + stz BG1TileMapHeight + stz BG1TileMapPtr + stz BG1TileMapPtr+2 + stz OneSecondCounter ]step equ 0 diff --git a/src/Defs.s b/src/Defs.s index c53d416..f8bcd28 100644 --- a/src/Defs.s +++ b/src/Defs.s @@ -108,13 +108,3 @@ DIRTY_BIT_BG1_X equ $0004 DIRTY_BIT_BG1_Y equ $0008 DIRTY_BIT_BG0_REFRESH equ $0010 DIRTY_BIT_BG1_REFRESH equ $0020 - - - - - - - - - - diff --git a/src/Graphics.s b/src/Graphics.s index 8d701ed..d92af12 100644 --- a/src/Graphics.s +++ b/src/Graphics.s @@ -121,7 +121,3 @@ WaitForVBL sep #$20 bpl :wait2 ; spin until transition into VBL rep #$20 rts - - - - diff --git a/src/Render.s b/src/Render.s index cdde2f9..22e6eba 100644 --- a/src/Render.s +++ b/src/Render.s @@ -84,8 +84,6 @@ _Render jsr _ApplyBG0XPos ; Patch the PEA instructions with exit BRA opcode jsr _ApplyBG1XPos ; Patch the PEA instructions with exit BRA opcode -; Copy any tiles that have come into view - ; The code fields are locked in now and reder to be rendered jsr ShadowOff @@ -126,31 +124,3 @@ _Render stz DirtyBits rts - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/TileMap.s b/src/TileMap.s index 0e40915..6403173 100644 --- a/src/TileMap.s +++ b/src/TileMap.s @@ -49,6 +49,12 @@ _UpdateBG0TileMap :BlkX equ tmp12 :BlkY equ tmp13 + lda TileMapPtr ; Do nothing if no data is set + ora TileMapPtr+2 + bne :valid + rts + +:valid lda StartY ; calculate the tile index of the current location lsr lsr @@ -390,6 +396,12 @@ _UpdateBG1TileMap :Top equ tmp2 :Bottom equ tmp3 + lda BG1TileMapPtr ; Do nothing if no data is set + ora BG1TileMapPtr+2 + bne :valid + rts + +:valid lda BG1StartY ; calculate the tile index of the current location lsr lsr @@ -648,19 +660,3 @@ _DrawRectBG1 pla rts - - - - - - - - - - - - - - - - diff --git a/src/Timer.s b/src/Timer.s index 328612b..8a301d1 100644 --- a/src/Timer.s +++ b/src/Timer.s @@ -62,6 +62,7 @@ InitTimers ; A = timer slot ID if C = 0 AddTimer ENT phb + php ; Save the input parameters phx pha @@ -135,6 +136,7 @@ RemoveTimer ENT :exit plb rtl + ; Execute the timer functions DoTimers ENT phb @@ -241,5 +243,6 @@ _DoTimers + diff --git a/src/blitter/BG0.s b/src/blitter/BG0.s index fb987da..31da819 100644 --- a/src/blitter/BG0.s +++ b/src/blitter/BG0.s @@ -1,7 +1,7 @@ ; Support routinges for the primary background _InitBG0 - jsr _ApplyBG0YPos - jsr _ApplyBG0XPos + lda #DIRTY_BIT_BG0_X+DIRTY_BIT_BG0_Y + tsb DirtyBits rts ; Copy a raw data file into the code field @@ -53,7 +53,7 @@ _CopyBinToField stz :line_cnt :rloop - lda :line_cnt ; get the pointer to the code field line + lda :line_cnt ; get the pointer to the code field line asl tax @@ -63,90 +63,88 @@ _CopyBinToField sta :dstptr+2 ; ldx #162 ; move backwards in the code field - ldy #0 ; move forward in the image data + ldy #0 ; move forward in the image data - lda #82 ; keep a running column count + lda #82 ; keep a running column count sta :col_cnt :cloop phy - lda [:srcptr],y ; load the picture data + lda [:srcptr],y ; load the picture data cmp :mask_color - beq :transparent ; a value of $0000 is transparent + beq :transparent ; a value of $0000 is transparent - jsr :toMask ; Infer a mask value for this. If it's $0000, then + jsr :toMask ; Infer a mask value for this. If it's $0000, then cmp #$0000 - bne :mixed ; the data is solid, otherwise mixed + bne :mixed ; the data is solid, otherwise mixed ; This is a solid word :solid lda [:srcptr],y - pha ; Save the data + pha ; Save the data - lda Col2CodeOffset,y ; Get the offset to the code from the line start + lda Col2CodeOffset,y ; Get the offset to the code from the line start tay - lda #$00F4 ; PEA instruction + lda #$00F4 ; PEA instruction sta [:dstptr],y iny pla - sta [:dstptr],y ; PEA operand + sta [:dstptr],y ; PEA operand bra :next :transparent - lda :mask_color ; Make sure we actually have to mask + lda :mask_color ; Make sure we actually have to mask cmp #$A5A5 beq :solid - lda Col2CodeOffset,y ; Get the offset to the code from the line start + lda Col2CodeOffset,y ; Get the offset to the code from the line start tay - lda #$B1 ; LDA (dp),y + lda #$B1 ; LDA (dp),y sta [:dstptr],y iny - lda 1,s ; load the saved Y-index - ora #$4800 ; put a PHA after the offset + lda 1,s ; load the saved Y-index + ora #$4800 ; put a PHA after the offset sta [:dstptr],y bra :next :mixed - sta :mask ; Save the mask - lda [:srcptr],y ; Refetch the screen data + sta :mask ; Save the mask + lda [:srcptr],y ; Refetch the screen data sta :data tyx - lda Col2CodeOffset,y ; Get the offset into the code field + lda Col2CodeOffset,y ; Get the offset into the code field tay - lda #$4C ; JMP exception + lda #$4C ; JMP exception sta [:dstptr],y iny - lda JTableOffset,x ; Get the address offset and add to the base address + lda JTableOffset,x ; Get the address offset and add to the base address clc adc :dstptr sta [:dstptr],y - ldy JTableOffset,x ; This points to the code fragment - lda 1,s ; load the offset + ldy JTableOffset,x ; This points to the code fragment + lda 1,s ; load the offset xba ora #$00B1 - sta [:dstptr],y ; write the LDA (--),y instruction + sta [:dstptr],y ; write the LDA (--),y instruction iny iny - iny ; advance to the AND #imm operand + iny ; advance to the AND #imm operand lda :mask sta [:dstptr],y iny iny - iny ; advance to the ORA #imm operand + iny ; advance to the ORA #imm operand lda :mask - eor #$FFFF ; invert the mask to clear up the data + eor #$FFFF ; invert the mask to clear up the data and :data sta [:dstptr],y :next ply -; dex -; dex iny iny @@ -167,10 +165,10 @@ _CopyBinToField :exit rts -:toMask pha ; save original +:toMask pha ; save original lda 1,s - eor :mask_color ; only identical bits produce zero + eor :mask_color ; only identical bits produce zero and #$F000 beq *+7 pea #$0000 @@ -212,7 +210,7 @@ _CopyBinToField sta 1,s pla - sta 1,s ; pop the saved word + sta 1,s ; pop the saved word pla rts @@ -245,7 +243,7 @@ _CopyPicToField stz :line_cnt :rloop - lda :line_cnt ; get the pointer to the code field line + lda :line_cnt ; get the pointer to the code field line asl tax @@ -255,76 +253,76 @@ _CopyPicToField sta :dstptr+2 ; ldx #162 ; move backwards in the code field - ldy #0 ; move forward in the image data + ldy #0 ; move forward in the image data - lda #80 ; keep a running column count + lda #80 ; keep a running column count ; lda #82 ; keep a running column count sta :col_cnt :cloop phy - lda [:srcptr],y ; load the picture data - beq :transparent ; a value of $0000 is transparent + lda [:srcptr],y ; load the picture data + beq :transparent ; a value of $0000 is transparent - jsr :toMask ; Infer a mask value for this. If it's $0000, then - bne :mixed ; the data is solid, otherwise mixed + jsr :toMask ; Infer a mask value for this. If it's $0000, then + bne :mixed ; the data is solid, otherwise mixed ; This is a solid word lda [:srcptr],y - pha ; Save the data + pha ; Save the data - lda Col2CodeOffset,y ; Get the offset to the code from the line start + lda Col2CodeOffset,y ; Get the offset to the code from the line start tay - lda #$00F4 ; PEA instruction + lda #$00F4 ; PEA instruction sta [:dstptr],y iny pla - sta [:dstptr],y ; PEA operand + sta [:dstptr],y ; PEA operand bra :next :transparent - lda Col2CodeOffset,y ; Get the offset to the code from the line start + lda Col2CodeOffset,y ; Get the offset to the code from the line start tay - lda #$B1 ; LDA (dp),y + lda #$B1 ; LDA (dp),y sta [:dstptr],y iny - lda 1,s ; load the saved Y-index - ora #$4800 ; put a PHA after the offset + lda 1,s ; load the saved Y-index + ora #$4800 ; put a PHA after the offset sta [:dstptr],y bra :next :mixed - sta :mask ; Save the mask - lda [:srcptr],y ; Refetch the screen data + sta :mask ; Save the mask + lda [:srcptr],y ; Refetch the screen data sta :data tyx - lda Col2CodeOffset,y ; Get the offset into the code field + lda Col2CodeOffset,y ; Get the offset into the code field tay - lda #$4C ; JMP exception + lda #$4C ; JMP exception sta [:dstptr],y iny - lda JTableOffset,x ; Get the address offset and add to the base address + lda JTableOffset,x ; Get the address offset and add to the base address clc adc :dstptr sta [:dstptr],y - ldy JTableOffset,x ; This points to the code fragment - lda 1,s ; load the offset + ldy JTableOffset,x ; This points to the code fragment + lda 1,s ; load the offset xba ora #$00B1 - sta [:dstptr],y ; write the LDA (--),y instruction + sta [:dstptr],y ; write the LDA (--),y instruction iny iny - iny ; advance to the AND #imm operand + iny ; advance to the AND #imm operand lda :mask sta [:dstptr],y iny iny - iny ; advance to the ORA #imm operand + iny ; advance to the ORA #imm operand lda :data sta [:dstptr],y @@ -379,8 +377,3 @@ _CopyPicToField bra *+5 ora #$000F rts - - - - - diff --git a/src/blitter/Blitter.s b/src/blitter/Blitter.s index 654f2e3..4c1c813 100644 --- a/src/blitter/Blitter.s +++ b/src/blitter/Blitter.s @@ -95,4 +95,3 @@ stk_save lda #0000 ; load the stack ; we don't do anything sprite related; just call function pointers provided to us. _RenderSprites rts - diff --git a/src/blitter/Horz.s b/src/blitter/Horz.s index aca5559..6a10e2e 100644 --- a/src/blitter/Horz.s +++ b/src/blitter/Horz.s @@ -345,7 +345,6 @@ _ApplyBG0XPos ; Special note, the SaveOpcode function stores the opcode *within* the code field as it is ; used in odd-aligned cases to determine how to draw the 8-bit value on the left edge of the ; screen - ; y is already set to :base_address tax ; :draw_count_x2 lda :exit_address ; Save from this location diff --git a/src/blitter/Template.s b/src/blitter/Template.s index 3a80de3..ea35e44 100644 --- a/src/blitter/Template.s +++ b/src/blitter/Template.s @@ -637,14 +637,3 @@ snippets lup 82 ]index equ ]index+1 --^ top - - - - - - - - - - -