diff --git a/core/boot.asm b/core/boot.asm new file mode 100644 index 0000000..36a0ccf --- /dev/null +++ b/core/boot.asm @@ -0,0 +1,121 @@ + +#importonce +#import "../core/pseudo.asm" +#import "../core/module.asm" + +#import "../core/system.asm" + +.filenamespace Boot + +.const INIT_IRQ = $fda3 +.const INIT_MEM = $fd50 +.const INIT_IO = $fd15 +.const INIT_VID = $ff5b +.const SCRN_CTRL = $d016 + +.const MAIN_COLOR = $03 +.const BORDER_COLOR = $05 +.const INTERRUPT_CTRL = $dc0d +.const NMSK_INTERRUPT_CTRL = $dd0d +.const TIMER_A_CTRL = $DC0E + +* = * "Boot Core" + + +// ======================================================== +// ////// METHODS ///////////////////////////////////////// +// ======================================================== + +// -------------------------------------------------------- +// coldstart - +// Power ON initialization +// -------------------------------------------------------- +coldStart: { + ldx #$FF + sei + txs + cld + stx SCRN_CTRL // Set Screen Bits + jsr INIT_IRQ // Prepare IRQ + jsr INIT_MEM // Init memory. Rewrite this routine to speed up boot process. + jsr INIT_IO // Init I/O + jsr INIT_VID // Init video + cli + jmp warmStart +} + +// -------------------------------------------------------- +// warmStart - +// Restore pressed or program restart after first Power ON +// -------------------------------------------------------- +warmStart: { + + sei + lda #$7f + sta INTERRUPT_CTRL // disable timer interrupts which can be generated by the two CIA chips + sta NMSK_INTERRUPT_CTRL // the kernal uses such an interrupt to flash the cursor and scan the keyboard, so we better + // stop it. + + lda INTERRUPT_CTRL // by reading this two registers we negate any pending CIA irqs. + lda NMSK_INTERRUPT_CTRL // if we don't do this, a pending CIA irq might occur after we finish setting up our irq. + // we don't want that to happen. + + // Disable 0e TIMER + lda #254 + and TIMER_A_CTRL + sta TIMER_A_CTRL + + ScreenClearColorRam($00) + ScreenClear(' ') + ScreenSetBorderColor(BORDER_COLOR) + ScreenSetBackgroundColor(MAIN_COLOR) + cli + + jsr Boot.init // Init Self as Module + jsr System.start // Start Core System + + // If System Exit - reboot + // TODO: We can print a message here + // and delay a bit... + jmp warmStart + +} + +// -------------------------------------------------------- +// init - +// Module Init. +// -------------------------------------------------------- +init: { + // Sequence matter + jsr Module.init + jsr Pseudo.init + jsr System.init + rts +} + +// -------------------------------------------------------- +// toDebug - +// Print debug info. +// -------------------------------------------------------- +toDebug: { + ModuleToDebug(module_type, module_name, version) + rts +} + + +// ======================================================== +// ////// DATA //////////////////////////////////////////// +// ======================================================== + +* = * "Boot Core Data" +module_type: .byte Module.TYPES.CORE +version: .byte 1, 0, 0 + +.encoding "screencode_mixed" +module_name: + .text "boot" + .byte 0 + + +#import "../core/mem_map.asm" + diff --git a/core/mem_map.asm b/core/mem_map.asm index c5c0f03..73b49ce 100644 --- a/core/mem_map.asm +++ b/core/mem_map.asm @@ -1,32 +1,37 @@ .filenamespace MemMap #importonce -.const SHELL_BUGGER_ADDR = $3000 -.const XSTACK_ADDRESS = $3100 -.const YSTACK_ADDRESS = $3200 +.const SHELL_BUFFER_ADDR = $1000 // 256 bytes (3000-30FF) +.const XSTACK_ADDRESS = $1100 // 256 bytes (3100-31FF) +.const YSTACK_ADDRESS = $1200 // 256 bytes (3200-32FF) +.const KEYB_RAM_CODE = $1300 // Safe to use > $1400 *=$2 "ZERO PAGE" virtual .namespace CORE { - yStackOffset: .byte 0 - xStackOffset: .byte 0 + // PHx/PLx pseudo commands + yStackOffset: .byte 0 // Y Stack offset used by phy/ply + xStackOffset: .byte 0 // X Stack offset used by phx/plx + .label XStack = XSTACK_ADDRESS // 256 bytes phy/ply stack buffer pointer + .label YStack = YSTACK_ADDRESS // 256 bytes phx/plx stack buffer pointer +} - .label XStack = XSTACK_ADDRESS // 256 bytes - .label YStack = YSTACK_ADDRESS // 256 bytes +.namespace PRINT { + TempStringPointer: .word 0 // Pointer to string address as it get printend to screen } .namespace SCREEN { - TempVideoPointer: .word 0 - TempStringPointer: .word 0 - CursorCol: .byte 0 - CursorRow: .byte 0 - ScrollUpTriggered: .byte 0 + TempVideoPointer: .word 0 // Pointer to video mem used to target char pos + CursorCol: .byte 0 // Actual cursor column position + CursorRow: .byte 0 // Actual cursor row position + ScrollUpTriggered: .byte 0 // Set to 1 if a scroll up was triggered } .namespace MATH { - factor1: .byte 0 - factor2: .byte 0 - result: .word 0 + factor1: .byte 0 // Factor 1 used in MUL ops + factor2: .byte 0 // Factor 2 used in MUL ops + + result: .word 0 // 16 Bit math operation result } .namespace KEYBOARD { @@ -40,6 +45,8 @@ SYS_Delay: .byte 0 SYS_Kount: .byte 0 SYS_Lstshf: .byte 0 + + .label keybRamCode = KEYB_RAM_CODE } .namespace MEMORY { @@ -63,7 +70,7 @@ XAML: .byte 0 XAMH: .byte 0 - .label buffer = SHELL_BUGGER_ADDR // 256 bytes + .label buffer = SHELL_BUFFER_ADDR // 256 bytes } diff --git a/libs/module.asm b/core/module.asm similarity index 94% rename from libs/module.asm rename to core/module.asm index adc47ae..cb69b99 100644 --- a/libs/module.asm +++ b/core/module.asm @@ -1,5 +1,5 @@ #importonce -#import "print.asm" +#import "../libs/print.asm" // ======================================================== // ////// MACROS ////////////////////////////////////////// @@ -101,13 +101,13 @@ printVersion: { sta MemMap.MODULE.versionPtr stx MemMap.MODULE.versionPtr+1 ldy #0 - jsr printNext + jsr printNext // Major lda #'.' PrintChar() - jsr printNext + jsr printNext // Minor lda #'.' PrintChar() - jsr printNext + jsr printNext // Revision rts printNext: lda (MemMap.MODULE.versionPtr), y @@ -154,8 +154,8 @@ printType: { // ======================================================== * = * "Module Lib Data" -module_type: .byte Module.TYPES.LIB -version: .byte 1, 1, 0 +module_type: .byte Module.TYPES.CORE +version: .byte 1, 2, 0 .encoding "screencode_mixed" module_name: diff --git a/core/pseudo.asm b/core/pseudo.asm index a35a829..c5d83db 100644 --- a/core/pseudo.asm +++ b/core/pseudo.asm @@ -1,6 +1,6 @@ #importonce #import "../core/mem_map.asm" -#import "../libs/module.asm" +#import "../core/module.asm" // ======================================================== diff --git a/core/init.asm b/core/system.asm similarity index 65% rename from core/init.asm rename to core/system.asm index 1b656eb..8f6dc42 100644 --- a/core/init.asm +++ b/core/system.asm @@ -1,54 +1,79 @@ #importonce +#import "../core/pseudo.asm" +#import "../core/module.asm" +#import "../core/boot.asm" #import "../libs/memory.asm" #import "../libs/math.asm" #import "../libs/print.asm" -#import "../core/keyboard.asm" -#import "../core/screen.asm" -#import "../core/pseudo.asm" -#import "../libs/module.asm" +#import "../libs/keyboard.asm" +#import "../libs/screen.asm" #import "../progs/woz_shell.asm" -.filenamespace Init +.filenamespace System -* = * "Init Core" +* = * "System Core" // ======================================================== // ////// METHODS ///////////////////////////////////////// // ======================================================== +// -------------------------------------------------------- +// start - +// System Start +// -------------------------------------------------------- +start: { + + + // Start Main Program + jsr WozShell.start + + // TODO: Program exited here + // We can ask program to set a ram param and let us know + // if exit is due to a sort of error. + + rts + + // TODO: Can we use Timed Interrupt to execute small system recurring tasks? +} + // -------------------------------------------------------- // init - // Module Init. // -------------------------------------------------------- init: { // Init All Modules - jsr Pseudo.init - jsr Module.init + // TODO: How we can make this dynamic? jsr Memory.init - jsr Math.init - jsr Print.init - jsr Keyboard.init jsr Screen.init + jsr Print.init + jsr Math.init + jsr Keyboard.init + jsr WozShell.init rts } + // -------------------------------------------------------- // toDebug - // Print debug info. // -------------------------------------------------------- toDebug: { // Debug All Modules + jsr Boot.toDebug ModuleToDebug(module_type, module_name, version) - jsr Keyboard.toDebug - jsr Screen.toDebug + jsr Pseudo.toDebug jsr Module.toDebug + + jsr Keyboard.toDebug + jsr Math.toDebug jsr Memory.toDebug jsr Print.toDebug - jsr Math.toDebug + jsr Screen.toDebug + jsr WozShell.toDebug rts } @@ -58,13 +83,13 @@ toDebug: { // ////// DATA //////////////////////////////////////////// // ======================================================== -* = * "Init Core Data" +* = * "System Core Data" module_type: .byte Module.TYPES.CORE -version: .byte 1, 1, 0 +version: .byte 1, 0, 0 .encoding "screencode_mixed" module_name: - .text "init" + .text "system" .byte 0 diff --git a/core/keyboard.asm b/libs/keyboard.asm similarity index 91% rename from core/keyboard.asm rename to libs/keyboard.asm index db40287..3764c59 100644 --- a/core/keyboard.asm +++ b/libs/keyboard.asm @@ -1,7 +1,7 @@ #importonce -#import "../libs/module.asm" +#import "../core/module.asm" #import "../libs/memory.asm" -#import "../libs/module.asm" +#import "../core/module.asm" .filenamespace Keyboard @@ -18,7 +18,11 @@ .const cSYS_DelayValue = 32 .const cKeybW_Row1 = $FE -* = * "Keyboard Module" +.const RASTER_LINE = $d012 + + + +* = * "Keyboard Lib" // ======================================================== // ////// METHODS ROM ///////////////////////////////////// @@ -49,7 +53,26 @@ init: { sta MemMap.KEYBOARD.SYS_Xmax // Clone self altering Methods to RAM - MemoryClone(cloneStart, cloneEnd, $1000) + MemoryClone(cloneStart, cloneEnd, MemMap.KEYBOARD.keybRamCode) + rts +} + +// -------------------------------------------------------- +// waitForKey - +// Loop until a new key is available. +// +// Result: +// A = Pressed key code +// -------------------------------------------------------- +waitForKey: { + loop: + lda #$FF + raster: + cmp RASTER_LINE // Raster done? + bne raster + jsr Keyboard.ReadKeyb + jsr Keyboard.GetKey + bcs loop rts } @@ -63,7 +86,7 @@ toDebug: { } // ======================================================== -// ////// KEYMAPPING RON ////////////////////////////////// +// ////// KEYMAPPING ROM ////////////////////////////////// // ======================================================== KeyMapVec: @@ -144,7 +167,7 @@ cloneStart: // bcs loop // // Key here is in A // -------------------------------------------------------- -.pseudopc $1000 { +.pseudopc MemMap.KEYBOARD.keybRamCode { ReadKeyb: { lda #