Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error Handler, MD Shell: Console scrolling #40

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 134 additions & 26 deletions modules/core/Console.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

; ---------------------------------------------------------------
Expand All @@ -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
Expand Down
20 changes: 11 additions & 9 deletions modules/core/Console.defs.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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 ; <Reserved>
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
Expand Down
4 changes: 2 additions & 2 deletions modules/core/Format_String.defs.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions modules/errorhandler-core/ErrorHandler.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Loading