From 1315c387c41892f7dbd40346f5c802c981097068 Mon Sep 17 00:00:00 2001 From: Martin Haye Date: Thu, 2 Jan 2014 15:27:31 -0800 Subject: [PATCH] Centralized debug code, fixed stack print and FATAL_ERROR code in mem mgr. --- Platform/Apple/virtual/build.xml | 6 + Platform/Apple/virtual/src/core/mem.s | 105 ++++++++++++++--- Platform/Apple/virtual/src/include/debug.i | 117 ++++++++++++++++++ Platform/Apple/virtual/src/raycast/render.s | 124 ++------------------ 4 files changed, 221 insertions(+), 131 deletions(-) create mode 100644 Platform/Apple/virtual/src/include/debug.i diff --git a/Platform/Apple/virtual/build.xml b/Platform/Apple/virtual/build.xml index cb382688..2c39ca84 100644 --- a/Platform/Apple/virtual/build.xml +++ b/Platform/Apple/virtual/build.xml @@ -17,6 +17,7 @@ + @@ -24,6 +25,10 @@ + + Building core. + + Building raycast. @@ -32,6 +37,7 @@ + diff --git a/Platform/Apple/virtual/src/core/mem.s b/Platform/Apple/virtual/src/core/mem.s index 3cfe05f5..84fc7fe3 100644 --- a/Platform/Apple/virtual/src/core/mem.s +++ b/Platform/Apple/virtual/src/core/mem.s @@ -216,10 +216,15 @@ FATAL_ERROR = $18 jmp main_dispatch jmp aux_dispatch +DEBUG = 1 + .include "../include/debug.i" + ;------------------------------------------------------------------------------ ; Variables isAuxCommand: .byte 0 +scanStart: + .byte 0 targetPage: .byte 0 nextLoaderVec: @@ -247,6 +252,9 @@ shared_dispatch: bne :+ stx targetPage rts +: cmp #FREE_MEMORY + bne :+ + jmp main_free : cmp #FATAL_ERROR bne :+ jmp fatalError @@ -259,8 +267,12 @@ aux_dispatch: bne :+ jmp aux_request : cmp #QUEUE_LOAD - bne shared_dispatch + bne :+ jmp aux_queueLoad +: cmp #FREE_MEMORY + bne :+ + jmp aux_free +: jmp shared_dispatch ;------------------------------------------------------------------------------ ; Print fatal error message (custom or predefined) and print the @@ -272,46 +284,65 @@ fatalError: jsr textinit jsr setvid jsr setkbd - jsr crout ; a couple newlines - jsr crout - ldy #0 ; start at first byte of message + ldy #0 +: lda fatalMsg,y ; print out prefix message + beq :+ + ora #$80 + jsr cout + iny + bne :- +: ldy #0 ; start at first byte of message : lda (pTmp),y beq :+ ora #$80 ; ensure hi-bit ASCII for cout jsr cout iny bne :- + .if DEBUG ; Print call stack -: jsr crout - tsx ; start at current stack pointer +: ldy #0 +: lda stackMsg,y + beq :+ + ora #$80 + jsr cout + iny + bne :- +: tsx ; start at current stack pointer @stackLoop: - lda 101,x ; JSR increments PC twice before pushing it + lda $101,x ; JSR increments PC twice before pushing it sec sbc #2 tay - lda 102,x + lda $102,x sbc #0 sta @load+2 and #$C0 ; avoid accidentally grabbing data from the IO area cmp #$C0 - beq :- + beq @next @load: lda $1000,y ; is there a JSR there? cmp #$20 - bne :- + bne @next ; no, it's probably not an actual call lda @load+2 jsr prbyte tya jsr prbyte lda #$A0 jsr cout +@next: inx ; work up to... cpx #$FF ; ...top of stack bcc @stackLoop + .endif + jsr crout ; Beep, and loop forever jsr bell loopForever: jmp loopForever +fatalMsg: + .byte $8D,"FATAL ERROR: ", 0 +stackMsg: + .byte $8D," Call stack: ", 0 ;------------------------------------------------------------------------------ init: @@ -343,8 +374,18 @@ init: ; Lock pages 0 and 1 in aux mem sta aux_pageTbl1 sta aux_pageTbl1+1 + .if DEBUG + jmp test + .endif rts +;------------------------------------------------------------------------------ + .if DEBUG +test: + DEBUG_STR "Testing memory manager." + jmp reservedErr + .endif + ;------------------------------------------------------------------------------ main_setup: lda #