diff --git a/modules/core/Console.asm b/modules/core/Console.asm index 788295d..c7d83d1 100644 --- a/modules/core/Console.asm +++ b/modules/core/Console.asm @@ -60,7 +60,10 @@ Console_Init: __global ; fallthrough ; --------------------------------------------------------------- -; Clears and resets console to the initial config +; A shorter initialization sequence used by sub-consoles sharing +; the same palette and graphics, but using a different nametable +; +; Also clears and resets console to the initial config ; --------------------------------------------------------------- ; INPUT: ; a1 Initial console config @@ -75,20 +78,18 @@ Console_Init: __global ; d0-d1, a1, a3 ; --------------------------------------------------------------- -Console_Reset: __global - move.l (a1)+, d5 ; d5 = VDP command with start on-screen position - ; fallthrough +Console_InitShared: __global + move.l a1, Console.VRAMConfigPtr(a3) ; Console RAM => Save VRAM config pointer + ;fallthrough ; --------------------------------------------------------------- -; A shorter initialization sequence used by sub-consoles sharing -; the same palette and graphics, but using a different nametable +; Clears and resets console screen to the initial state ; --------------------------------------------------------------- ; INPUT: -; a1 Shared console config +; a1 Initial console config ; a3 Console RAM pointer ; a5 VDP Control Port ($C00004) ; a6 VDP Data Port ($C00000) -; d5 .l VDP command with start on-screen position ; ; OUTPUT: ; d5 .l Current on-screen position @@ -97,31 +98,39 @@ Console_Reset: __global ; d0-d1, a1, a3 ; --------------------------------------------------------------- -Console_InitShared: __global - ; WARNING! Make sure a5 and a6 are properly set when calling this fragment separately +Console_Reset: __global + move.l (a1)+, d5 ; d5 = VDP command with start on-screen position + moveq #0, d0 + move.l (a1)+, (a5) ; VDP => Setup VRAM write to HScroll + move.l d0, (a6) ; VDP => Reset HScroll (both planes) + move.l #$00104000, d1 + add.w (a1)+, d1 + swap d1 + move.l d1, (a5) ; VDP => Setup VSRAM write + move.l d0, (a6) ; VDP => Reset VScroll (both planes) ; Init Console RAM - move.l a3, usp ; remember Console RAM pointer in USP to restore it in later calls - move.l d5, (a3)+ ; Console RAM => set current position (long) - move.l d5, (a3)+ ; Console RAM => set start-of-line position (long) - move.l (a1)+, (a3)+ ; Console RAM => copy number of characters per line (word) + characters remaining for the current line (word) - move.l (a1)+, (a3)+ ; Console RAM => copy base pattern (word) + screen row size (word) - move.w #_ConsoleMagic<<8, (a3)+; Console RAM => set magic number, clear reserved byte + move.l a3, usp ; remember Console RAM pointer in USP to restore it in later calls + move.l d5, (a3)+ ; Console RAM => set current position (long) + move.l d5, (a3)+ ; Console RAM => set start-of-line position (long) + move.l (a1)+, (a3)+ ; Console RAM => copy number of characters per line (word) + characters remaining for the current line (word) + move.l (a1)+, (a3)+ ; Console RAM => copy base pattern (word) + screen row size (word) + move.w d0, (a3)+ ; Console RAM => clear Y- and X-tile scrolling + move.b #_ConsoleMagic, (a3)+ ; Console RAM => set magic number ; Clear screen - move.l d5, (a5) ; VDP => Setup VRAM for screen namespace - moveq #0, d0 ; d0 = fill pattern - move.w (a1)+, d1 ; d1 = size of screen in tiles - 1 - bsr.s Console_FillTile ; fill screen + move.l d5, (a5) ; VDP => Setup VRAM for screen namespace + ;moveq #0, d0 ; d0 = fill pattern -- OPTIMIZED OUT + move.w (a1)+, d1 ; d1 = size of screen in tiles - 1 + bsr.s Console_FillTile ; fill screen - vram $0000, (a5) ; VDP => Setup VRAM at tile 0 - ;moveq #0, d0 ; d0 = fill pattern -- OPTIMIZED OUT - moveq #0, d1 ; d1 = number of tiles to fill - 1 - bsr.s Console_FillTile ; clear first tile + vram $0000, (a5) ; VDP => Setup VRAM at tile 0 + ;moveq #0, d0 ; d0 = fill pattern -- OPTIMIZED OUT + moveq #0, d1 ; d1 = number of tiles to fill - 1 + bsr.s Console_FillTile ; clear first tile ; Finalize - move.w #$8174, (a5) ; VDP => Enable display - move.l d5, (a5) ; VDP => Enable console for writing + move.w #$8174, (a5) ; VDP => Enable display rts ; --------------------------------------------------------------- @@ -133,6 +142,105 @@ Console_FillTile: rts +; =============================================================== +; --------------------------------------------------------------- +; Clears the entire console and reset it to the initial state +; --------------------------------------------------------------- + +Console_Clear: __global + move.l a3, -(sp) + move.l usp, a3 + cmp.b #_ConsoleMagic, Console.Magic(a3) + bne.s @quit + + movem.l d0-d1/d5/a1/a5-a6, -(sp) + lea VDP_Ctrl, a5 + lea -4(a5), a6 + movea.l Console.VRAMConfigPtr(a3), a1 + jsr Console_Reset(pc) + movem.l (sp)+, d0-d1/d5/a1/a5-a6 + +@quit: + move.l (sp)+, a3 + rts + +; =============================================================== +; --------------------------------------------------------------- +; +; --------------------------------------------------------------- +; INPUT: +; d0 .b X-tile scrolling +; d1 .b Y-tile scrolling +; --------------------------------------------------------------- + +Console_SetXYTileScrollPosition: __global + KDebug.WriteLine "Console_SetXYTileScrollPosition: x=%<.b d0>, y=%<.b d1>" + + move.l a3, -(sp) + move.l usp, a3 + cmp.b #_ConsoleMagic, Console.Magic(a3) + bne.s @quit + + move.l d2, -(sp) + move.l a6, -(sp) + lea VDP_Data, a6 + + move.b d0, Console.XScrollTile(a3) + move.b d1, Console.YScrollTile(a3) + + move.w Console.ScreenRowSz(a3), d2 ; d2 = number of bytes in a row (usually $80) + lsr.w d2 ; d2 = number of tiles in a row (usually $40) + subq.w #1, d2 ; d2 = number of tiles in a row as a mask (usually $3F) + movea.l Console.VRAMConfigPtr(a3), a3 ; a3 = VRAM config pointer + addq.w #4, a3 ; skip screen start address + move.l (a3)+, 4(a6) ; VDP => Set HSRAM address + and.b d0, d2 + lsl.w #3, d2 ; d2 = HScroll value in pixels + neg.w d2 ; '' + move.w d2, (a6) ; VDP => Set HScroll value + move.w d2, (a6) ; '' + + move.l #$00104000, d2 + add.w (a3)+, d2 + swap d2 + move.l d2, 4(a6) ; VDP => Set VSRAM address + moveq #$3F, d2 + and.b d1, d2 + lsl.w #3, d2 ; d2 = VScroll value in pixels + move.w d2, (a6) ; VDP => Set VScroll value + move.w d2, (a6) ; '' + ;KDebug.WriteLine "data=%<.w d2>" + + move.l (sp)+, d2 + move.l (sp)+, a6 + +@quit: + move.l (sp)+, a3 + rts + +; =============================================================== +; --------------------------------------------------------------- +; +; --------------------------------------------------------------- +; OUTPUT: +; d0 .b X-tile scrolling +; d1 .b Y-tile scrolling +; --------------------------------------------------------------- + +Console_GetXYTileScrollPosition: __global + move.l a3, -(sp) + move.l usp, a3 + cmp.b #_ConsoleMagic, Console.Magic(a3) + bne.s @quit + + move.b Console.XScrollTile(a3), d0 + move.b Console.YScrollTile(a3), d1 + +@quit: + move.l (sp)+, a3 + rts + + ; =============================================================== ; --------------------------------------------------------------- ; Setup console cursor position based on XY coordinates diff --git a/modules/core/Console.defs.asm b/modules/core/Console.defs.asm index 8221aba..bb954c9 100644 --- a/modules/core/Console.defs.asm +++ b/modules/core/Console.defs.asm @@ -15,16 +15,18 @@ _CONSOLE_DEFS: equ 1 ; --------------------------------------------------------------- rsreset -Console_RAM equ __rs -Console.ScreenPosReq rs.l 1 ; current on-screen position request for VDP +Console_RAM: equ __rs +Console.ScreenPosReq: rs.l 1 ; current on-screen position request for VDP Console.ScreenRowReq: rs.l 1 ; start of row position request for VDP -Console.CharsPerLine rs.w 1 ; d2 number of characters per line -Console.CharsRemaining rs.w 1 ; d3 remaining number of characters -Console.BasePattern rs.w 1 ; d4 base pattern -Console.ScreenRowSz rs.w 1 ; d6 row size within screen position -Console.Magic rs.b 1 ; should contain a magic number to ensure this is valid console memory area - rs.b 1 ; -Console_RAM.size equ __rs-Console_RAM +Console.CharsPerLine: rs.w 1 ; d2 number of characters per line +Console.CharsRemaining: rs.w 1 ; d3 remaining number of characters +Console.BasePattern: rs.w 1 ; d4 base pattern +Console.ScreenRowSz: rs.w 1 ; d6 row size within screen position +Console.YScrollTile: rs.b 1 ; start tile for Y-scrolling (e.g. $02 = scroll past first two rows) +Console.XScrollTile: rs.b 1 ; start tile for X-scrolling (e.g. $02 = scroll past first two cols) +Console.Magic: equ __rs ; should contain a magic number to ensure this is valid console memory area (uses MSB of the next longword) +Console.VRAMConfigPtr: rs.l 1 ; pointer to Console's initial VRAM config (part of Console config containing VRAM and VSRAM offsets for the screen) +Console_RAM.size: equ __rs-Console_RAM ; --------------------------------------------------------------- ; Constants diff --git a/modules/core/Format_String.defs.asm b/modules/core/Format_String.defs.asm index 343a91c..b084889 100644 --- a/modules/core/Format_String.defs.asm +++ b/modules/core/Format_String.defs.asm @@ -119,9 +119,9 @@ __FSTRING_GenerateDecodedString & ; Validate format setting ("param") if strlen("\__param")<1 - __param: substr ,,"hex" ; if param is ommited, set it to "hex" + __param: substr ,,"_hex" ; if param is ommited, set it to "hex" elseif strcmp("\__param","signed") - __param: substr ,,"hex+signed" ; if param is "signed", correct it to "hex+signed" + __param: substr ,,"_hex+signed" ; if param is "signed", correct it to "hex+signed" endif if (\__param < $80) diff --git a/modules/errorhandler-core/ErrorHandler.asm b/modules/errorhandler-core/ErrorHandler.asm index 3de3e62..f731921 100644 --- a/modules/errorhandler-core/ErrorHandler.asm +++ b/modules/errorhandler-core/ErrorHandler.asm @@ -24,6 +24,8 @@ VRAM_Font: equ (('!'-1)*$20) VRAM_ErrorScreen: equ $8000 +VRAM_ErrorHScroll: equ $FC00 +VSRAM_ErrorVScroll: equ $00 _white: equ 0 _yellow: equ 1<<13 @@ -528,7 +530,7 @@ ErrorHandler_VDPConfig: __global dc.w $8700 ; $07, set backdrop color dc.w $8B00 ; $0B, set VScroll=full, HScroll=full dc.w $8C81 ; $0C, use 320 pixels horizontal resolution - dc.w $8D00 ; $0D, set HScroll table offset to $0000 + dc.w $8D3F ; $0D, set HScroll table offset to $FC00 dc.w $8F02 ; $0F, set auto-increment to $02 dc.w $9011 ; $10, use 512x512 plane resolution dc.w $9100 ; $11, reset Window X-position @@ -595,9 +597,9 @@ ErrorHandler_ConsoleConfig: ErrorHandler_ConsoleConfig_Initial: __global dcvram VRAM_ErrorScreen ; screen start address / plane nametable pointer - ; fallthrough + dcvram VRAM_ErrorHScroll ; HSRAM address + dc.w VSRAM_ErrorVScroll ; VSRAM address -ErrorHandler_ConsoleConfig_Shared: __global dc.w 40 ; number of characters per line dc.w 40 ; number of characters on the first line (meant to be the same as the above) dc.w 0 ; base font pattern (tile id for ASCII $00 + palette flags) diff --git a/modules/errorhandler-core/Extensions.asm b/modules/errorhandler-core/Extensions.asm index 35861d3..b8211e6 100644 --- a/modules/errorhandler-core/Extensions.asm +++ b/modules/errorhandler-core/Extensions.asm @@ -39,28 +39,6 @@ ErrorHandler_ConsoleOnly: __global rts ; jump to return address -; ============================================================================= -; ----------------------------------------------------------------------------- -; Clears currently used console -; ----------------------------------------------------------------------------- - -ErrorHandler_ClearConsole: __global - move.l a3, -(sp) - move.l usp, a3 - cmp.b #_ConsoleMagic, Console.Magic(a3) - bne.s @quit - - movem.l d0-d1/d5/a1/a5-a6, -(sp) - lea VDP_Ctrl, a5 ; a5 = VDP_Ctrl - lea -4(a5), a6 ; a6 = VDP_Data - lea ErrorHandler_ConsoleConfig_Initial(pc), a1 - jsr Console_Reset(pc) - movem.l (sp)+, d0-d1/d5/a1/a5-a6 -@quit: - move.l (sp)+, a3 - rts - - ; ============================================================================= ; ----------------------------------------------------------------------------- ; Pause console program executions until A/B/C are pressed @@ -73,9 +51,9 @@ ErrorHandler_PauseConsole: __global bne.s @quit move.w #0, -(sp) ; allocate joypad memory - bsr.s Joypad_Wait_ABCStart ; extra call to initialize joypad bitfield and avoid misdetecting pressed buttons + bsr.s ReadJoypad_And_CheckABCStart ; extra call to initialize joypad bitfield and avoid misdetecting pressed buttons @loop: - bsr.s Joypad_Wait_ABCStart ; is A/B/C pressed? + bsr.s ReadJoypad_And_CheckABCStart ; is A/B/C pressed? beq.s @loop ; if not, branch addq.w #2, sp @@ -85,6 +63,42 @@ ErrorHandler_PauseConsole: __global rts +; ============================================================================= +; ----------------------------------------------------------------------------- +; Initialize joypads +; ----------------------------------------------------------------------------- + +InitJoypad: + moveq #$40,d0 + move.b d0, ($A10009).l ; init port 1 (joypad 1) + move.b d0, ($A1000B).l ; init port 2 (joypad 2) + move.b d0, ($A1000D).l ; init port 3 (extra) + rts + +; ----------------------------------------------------------------------------- +; Reads input from joypad +; ----------------------------------------------------------------------------- + +ReadJoypad: + move.b #0, (a1) ; command to poll for A/Start + nop ; wait for port (0/1) + moveq #$FFFFFFC0, d1 ; wait for port (1/1) ... and do useful work (0/1) + move.b (a1), d0 ; get data for A/Start + lsl.b #2, d0 + move.b #$40, (a1) ; command to poll for B/C/UDLR + nop ; wait for port (0/1) + and.b d1, d0 ; wait for port (1/1) ... and do useful work (1/1) + move.b (a1), d1 ; get data for B/C/UDLR + andi.b #$3F, d1 + or.b d1, d0 ; d0 = held buttons bitfield (negated) + not.b d0 ; d0 = held buttons bitfield (normal) + move.b (a0), d1 ; d1 = previously held buttons + eor.b d0, d1 ; toggle off buttons that are being pressed + move.b d0, (a0)+ ; put raw controller input (for held buttons) + and.b d0, d1 + move.b d1, (a0)+ ; put pressed controller input + rts + ; ----------------------------------------------------------------------------- ; Pause console program executions until A/B/C or Start are pressed ; ----------------------------------------------------------------------------- @@ -98,8 +112,8 @@ ErrorHandler_PauseConsole: __global ; d0-d1 / a0-a1 ; ----------------------------------------------------------------------------- -Joypad_Wait_ABCStart: - bsr.s VSync +ReadJoypad_And_CheckABCStart: + bsr VSync lea 4(sp), a0 ; a0 = Joypad memory lea $A10003, a1 ; a1 = Joypad 1 Port bsr.s ReadJoypad @@ -115,15 +129,21 @@ Joypad_Wait_ABCStart: ErrorHandler_PagesController: __global movem.l d0-a6, -(sp) ; back up all the registers ... + bsr.s InitJoypad ; initialize joypads (in case they weren't initilialized before) + + lea -Console_RAM.size(sp), sp ; allocate memory for console + move.l usp, a0 + move.l a0, -(sp) ; save original debugger's console state move.w #0, -(sp) ; allocate joypad memory - bsr.s Joypad_Wait_ABCStart ; extra call to initialize joypad bitfield and avoid misdetecting pressed buttons + + bsr.s ReadJoypad_And_CheckABCStart; extra call to initialize joypad bitfield and avoid misdetecting pressed buttons @MainLoop: lea VDP_Ctrl, a5 ; a5 = VDP_Ctrl lea -4(a5), a6 ; a6 = VDP_Data - bsr.s Joypad_Wait_ABCStart ; Start/A/B/C pressed? - beq.s @MainLoop ; if not, branch + bsr.s ReadJoypad_And_CheckABCStart; Start/A/B/C pressed? + beq.s @HandleConsoleScrolling ; if not, branch bmi.s @ShowMainErrorScreen ; if Start pressed, branch ; Detect debugger to run depending on currently pressed button (A/B/C) @@ -139,10 +159,8 @@ ErrorHandler_PagesController: __global movea.l d0, a0 ; Initialize console for the debugger - lea -Console_RAM.size(sp), sp ; allocate memory for console - lea ErrorHandler_ConsoleConfig_Shared(pc), a1 - lea (sp), a3 ; a3 = Console RAM - vram VRAM_DebuggerPage, d5 ; d5 = Screen start address + lea @ConsoleConfig_SecondaryDebugger(pc), a1 + lea 2+4+Console_RAM.size(sp), a3 ; a3 = Console RAM jsr Console_InitShared(pc) ; Display debugger's own console @@ -150,22 +168,82 @@ ErrorHandler_PagesController: __global move.l d5, (a5) ; restore last VDP write address ; Execute the debugger - pea @DestroyDebugger(pc) - pea (a0) ; use debbuger's context upon return - movem.l Console_RAM.size+2+4(sp), d0-a6 ; switch to original registers ... - rts ; switch to debugger's context ... + pea @MainLoop(pc) + pea (a0) ; use debbuger's context upon return + movem.l 2+4+Console_RAM.size+4(sp), d0-a6 ; switch to original registers ... + rts ; switch to debugger's context ... + + ; ----------------------------------------------------------------------------- + @HandleConsoleScrolling: + move.b 1(sp), d0 ; d0 = pressed buttons, extacted by `ReadJoypad_And_CheckABCStart` + bsr.s HandleConsoleScrolling + bra @MainLoop + + ; ----------------------------------------------------------------------------- + @ShowMainErrorScreen: + move.l ErrorHandler_VDPConfig_Nametables(pc), (a5) + move.l 2(sp), a0 + move.l a0, usp ; restore console state + moveq #0, d0 + moveq #0, d1 + bsr Console_SetXYTileScrollPosition ; reset console scrolling + bra @MainLoop ; ----------------------------------------------------------------------------- -@DestroyDebugger: - lea Console_RAM.size(sp), sp ; deallocate console memory - bra.s @MainLoop +@ConsoleConfig_SecondaryDebugger: + dcvram VRAM_DebuggerPage ; screen start address / plane nametable pointer + dcvram VRAM_ErrorHScroll ; HSRAM address + dc.w VSRAM_ErrorVScroll ; VSRAM address + dc.w 40 ; number of characters per line + dc.w 40 ; number of characters on the first line (meant to be the same as the above) + dc.w 0 ; base font pattern (tile id for ASCII $00 + palette flags) + dc.w $80 ; size of screen row (in bytes) + + dc.w $2000/$20-1 ; size of screen (in tiles - 1) + +; ----------------------------------------------------------------------------- +; +; ----------------------------------------------------------------------------- +; INPUT: +; d0 .b Pressed buttons bitfield +; +; USES: +; d0-d1 ; ----------------------------------------------------------------------------- -@ShowMainErrorScreen: - ; WARNING! Make sure a5 is "VDP_Ctrl"! - move.l ErrorHandler_VDPConfig_Nametables(pc), (a5) - bra.s @MainLoop +HandleConsoleScrolling: + lsl.b #4, d0 + bmi.s @ScrollRight + add.b d0, d0 + bmi.s @ScrollLeft + add.b d0, d0 + bmi.s @ScrollDown + add.b d0, d0 + bpl.s @Quit + +@ScrollUp: + bsr Console_GetXYTileScrollPosition + subq.b #1, d1 + bra Console_SetXYTileScrollPosition + +@ScrollDown: + bsr Console_GetXYTileScrollPosition + addq.b #1, d1 + bra Console_SetXYTileScrollPosition + +@ScrollLeft: + bsr Console_GetXYTileScrollPosition + subq.b #1, d0 + bra Console_SetXYTileScrollPosition + +@ScrollRight: + bsr Console_GetXYTileScrollPosition + addq.b #1, d0 + bra Console_SetXYTileScrollPosition + +@Quit: + rts ; ============================================================================= ; ----------------------------------------------------------------------------- @@ -186,31 +264,6 @@ VSync: __global rts -; ============================================================================= -; ----------------------------------------------------------------------------- -; Reads input from joypad -; ----------------------------------------------------------------------------- - -ReadJoypad: - move.b #0, (a1) ; command to poll for A/Start - nop ; wait for port (0/1) - moveq #$FFFFFFC0, d1 ; wait for port (1/1) ... and do useful work (0/1) - move.b (a1), d0 ; get data for A/Start - lsl.b #2, d0 - move.b #$40, (a1) ; command to poll for B/C/UDLR - nop ; wait for port (0/1) - and.b d1, d0 ; wait for port (1/1) ... and do useful work (1/1) - move.b (a1), d1 ; get data for B/C/UDLR - andi.b #$3F, d1 - or.b d1, d0 ; d0 = held buttons bitfield (negated) - not.b d0 ; d0 = held buttons bitfield (normal) - move.b (a0), d1 ; d1 = previously held buttons - eor.b d0, d1 ; toggle off buttons that are being pressed - move.b d0, (a0)+ ; put raw controller input (for held buttons) - and.b d0, d1 - move.b d1, (a0)+ ; put pressed controller input - rts - ; ----------------------------------------------------------------------------- ; Extra debugger to button mappings ; ----------------------------------------------------------------------------- diff --git a/modules/errorhandler/Debugger.Macros.AS.asm b/modules/errorhandler/Debugger.Macros.AS.asm index 130fc5e..db45ecd 100644 --- a/modules/errorhandler/Debugger.Macros.AS.asm +++ b/modules/errorhandler/Debugger.Macros.AS.asm @@ -217,7 +217,7 @@ Console macro argument1, argument2 #endif case "clear" move.w sr, -(sp) - jsr MDDBG__ErrorHandler_ClearConsole + jsr MDDBG__Console_Clear move.w (sp)+, sr case "pause" diff --git a/modules/errorhandler/Debugger.Macros.ASM68K.asm b/modules/errorhandler/Debugger.Macros.ASM68K.asm index 7f27c51..3d21ef1 100644 --- a/modules/errorhandler/Debugger.Macros.ASM68K.asm +++ b/modules/errorhandler/Debugger.Macros.ASM68K.asm @@ -211,7 +211,7 @@ Console & #endif elseif strcmp("\0","clear")|strcmp("\0","Clear") move.w sr, -(sp) - jsr MDDBG__ErrorHandler_ClearConsole + jsr MDDBG__Console_Clear move.w (sp)+, sr elseif strcmp("\0","pause")|strcmp("\0","Pause")