From 5b8f75ecd1063bb4190903ce50aabaa2a20323fc Mon Sep 17 00:00:00 2001 From: Martin Haye Date: Fri, 5 Jun 2015 07:54:09 -0700 Subject: [PATCH] Refactored debug macro support to be always present, and provided by the memory manager. --- Platform/Apple/virtual/src/core/mem.s | 136 +++++++++++++++++++-- Platform/Apple/virtual/src/include/debug.i | 125 ++----------------- 2 files changed, 138 insertions(+), 123 deletions(-) diff --git a/Platform/Apple/virtual/src/core/mem.s b/Platform/Apple/virtual/src/core/mem.s index 9b90ecb3..796b5db6 100644 --- a/Platform/Apple/virtual/src/core/mem.s +++ b/Platform/Apple/virtual/src/core/mem.s @@ -53,11 +53,25 @@ codeBegin: jmp main_dispatch jmp aux_dispatch jmp __asmPlasm + +; Vectors for debug macros + jmp __writeStr + jmp __prByte + jmp __prSpace + jmp __prWord + jmp __prA + jmp __prX + jmp __prY + jmp __crout + jmp __waitKey + +;------------------------------------------------------------------------------ +; Relocation code locationCheck: jsr monrts tsx lda $100,x - cmp #>* + cmp #>locationCheck bne + jmp init + sta pSrc+1 @@ -91,6 +105,117 @@ fixupHint: !word 0 ;------------------------------------------------------------------------------ !if DEBUG { !source "../include/debug.i" } +; Debug code to support macros + +; Fetch a byte pointed to by the first entry on the stack, and advance that entry. +_getStackByte !zone { + inc $101,x + bne + + inc $102,x ++ lda $101,x + sta .ld+1 + lda $102,x + sta .ld+2 +.ld: lda $2000 + rts +} + +; Support to print a string following the JSR, in high or low bit ASCII, +; terminated by zero. If the string has a period "." it will be followed +; automatically by a carriage return. Preserves all registers. +__writeStr: !zone { + jsr iosave + tsx +.loop: jsr _getStackByte + beq .done + jsr cout + cmp #$AE ; "." + bne .loop + jsr crout + jmp .loop +.done: jmp iorest +} + +__prByte: !zone { + jsr iosave + ldy #0 + ; fall through to _prShared... +} + +_prShared: !zone { + tsx + jsr _getStackByte + sta .ld+1 + jsr _getStackByte + sta .ld+2 +.ld: lda $2000,y + jsr prbyte + dey + bpl .ld + +prSpace + jmp iorest +} + +__prSpace: !zone { + php + pha + lda #$A0 + jsr cout + pla + plp + rts +} + +__prWord: !zone { + jsr iosave + ldy #1 + bne _prShared ; always taken +} + +__prA: !zone { + php + pha + jsr prbyte + pla + plp + rts +} + +__prX: !zone { + php + pha + txa + jsr prbyte + pla + plp + rts +} + +__prY: !zone { + php + pha + tya + jsr prbyte + pla + plp + rts +} + +__crout: !zone { + php + pha + jsr crout + pla + plp + rts +} + +__waitKey: !zone { + jsr iosave + jsr rdkey + jmp iorest +} + ;------------------------------------------------------------------------------ grabSegment: !zone ; Input: None @@ -415,13 +540,7 @@ fatalError: !zone init: !zone ; put something interesting on the screen :) jsr home - ldx #0 -- lda .welcomeStr,x - beq + - jsr cout - inx - bne - -+ + +prStr : !text "Welcome to Mythos.",$8D,0 ; relocate ProDOS to the aux LC bank jsr moveProDOS ; close all files @@ -571,7 +690,6 @@ init: !zone jsr mainLoader ldx #$10 ; initial eval stack index .gomod: jmp $1111 ; jump to module for further bootstrapping -.welcomeStr !text "Welcome to MythOS.",$8D,0 ;------------------------------------------------------------------------------ moveProDOS: !zone diff --git a/Platform/Apple/virtual/src/include/debug.i b/Platform/Apple/virtual/src/include/debug.i index 115c93d3..31c8811d 100644 --- a/Platform/Apple/virtual/src/include/debug.i +++ b/Platform/Apple/virtual/src/include/debug.i @@ -1,3 +1,14 @@ +; Debug support routines (defined in core/mem.s) +_writeStr = $80C +_prByte = _writeStr+3 +_prSpace = _prByte+3 +_prWord = _prSpace+3 +_prA = _prWord+3 +_prX = _prA+3 +_prY = _prX+3 +_crout = _prY+3 +_waitKey = _crout+3 + ; Debug macros !macro prStr { jsr _writeStr @@ -81,117 +92,3 @@ jsr _waitKey } -; Debug code to support macros - - jmp _afterDebug - -; Fetch a byte pointed to by the first entry on the stack, and advance that entry. -_getStackByte !zone { - inc $101,x - bne + - inc $102,x -+ lda $101,x - sta .ld+1 - lda $102,x - sta .ld+2 -.ld: lda $2000 - rts -} - -; Support to print a string following the JSR, in high or low bit ASCII, -; terminated by zero. If the string has a period "." it will be followed -; automatically by a carriage return. Preserves all registers. -_writeStr: !zone { - jsr iosave - tsx -.loop: jsr _getStackByte - beq .done - jsr cout - cmp #$AE ; "." - bne .loop - jsr crout - jmp .loop -.done: jmp iorest -} - -_prByte: !zone { - jsr iosave - ldy #0 - ; fall through to _prShared... -} - -_prShared: !zone { - tsx - jsr _getStackByte - sta .ld+1 - jsr _getStackByte - sta .ld+2 -.ld: lda $2000,y - jsr prbyte - dey - bpl .ld - +prSpace - jmp iorest -} - -_prSpace: !zone { - php - pha - lda #$A0 - jsr cout - pla - plp - rts -} - -_prWord: !zone { - jsr iosave - ldy #1 - bne _prShared ; always taken -} - -_prA: !zone { - php - pha - jsr prbyte - pla - plp - rts -} - -_prX: !zone { - php - pha - txa - jsr prbyte - pla - plp - rts -} - -_prY: !zone { - php - pha - tya - jsr prbyte - pla - plp - rts -} - -_crout: !zone { - php - pha - jsr crout - pla - plp - rts -} - -_waitKey: !zone { - jsr iosave - jsr rdkey - jmp iorest -} - -_afterDebug: