From 222326bb1a388975f817e6b39ea39ef14363f447 Mon Sep 17 00:00:00 2001 From: stid Date: Sun, 12 Jan 2020 16:52:10 -0800 Subject: [PATCH] Cleanup & Standardize code --- core/init.asm | 33 ++++++--- core/keyboard.asm | 86 ++++++++++++++++------ core/screen.asm | 121 +++++++++++++++++++++++++------ libs/math.asm | 46 ++++++++---- libs/memory.asm | 106 +++++++++++++++++++++------ libs/module.asm | 172 +++++++++++++++++++++++++++++++++++--------- libs/print.asm | 105 ++++++++++++++++----------- main.asm | 2 +- progs/woz_shell.asm | 28 ++++++-- 9 files changed, 526 insertions(+), 173 deletions(-) diff --git a/core/init.asm b/core/init.asm index 6e6a410..9a416f4 100644 --- a/core/init.asm +++ b/core/init.asm @@ -5,16 +5,22 @@ #import "../libs/print.asm" #import "../core/keyboard.asm" #import "../core/screen.asm" +#import "../libs/module.asm" #import "../progs/woz_shell.asm" .filenamespace Init * = * "Init Core" -// ------------------------------------ -// METHODS -// ------------------------------------ +// ======================================================== +// ////// METHODS ///////////////////////////////////////// +// ======================================================== + +// -------------------------------------------------------- +// init - +// Module Init. +// -------------------------------------------------------- init: { // Init All Modules jsr Memory.init @@ -27,9 +33,13 @@ init: { rts } +// -------------------------------------------------------- +// toDebug - +// Print debug info. +// -------------------------------------------------------- toDebug: { // Debug All Modules - ModuleDefaultToDebug(module_name, version) + ModuleToDebug(module_type, module_name, version) jsr Keyboard.toDebug jsr Screen.toDebug jsr Module.toDebug @@ -42,14 +52,19 @@ toDebug: { -// ------------------------------------ -// DATA -// ------------------------------------ +// ======================================================== +// ////// DATA //////////////////////////////////////////// +// ======================================================== * = * "Init Core Data" -version: .byte 1, 0, 0 +module_type: .byte Module.TYPES.CORE +version: .byte 1, 1, 0 + +.encoding "screencode_mixed" module_name: - .text "core:init" + .text "init" .byte 0 + + #import "../core/mem_map.asm" diff --git a/core/keyboard.asm b/core/keyboard.asm index a00e96d..86a55a6 100644 --- a/core/keyboard.asm +++ b/core/keyboard.asm @@ -1,30 +1,33 @@ #importonce #import "../libs/module.asm" #import "../libs/memory.asm" - -// ------------------------------------ -// MACROS -// ------------------------------------ +#import "../libs/module.asm" .filenamespace Keyboard -* = * "Keyboard Module" -// ------------------------------------ -// CONSTANTS -// ------------------------------------ +// ======================================================== +// ////// CONSTANTS /////////////////////////////////////// +// ======================================================== + + .const CIA1_KeybWrite = $DC00 .const CIA1_KeybRead = $DC01 .const cSYS_DelayValue = 32 .const cKeybW_Row1 = $FE +* = * "Keyboard Module" -// ------------------------------------ -// METHODS -// ------------------------------------ +// ======================================================== +// ////// METHODS ROM ///////////////////////////////////// +// ======================================================== +// -------------------------------------------------------- +// init - +// Module Init. +// -------------------------------------------------------- init: { lda #64 sta MemMap.KEYBOARD.SYS_Lstx @@ -45,16 +48,24 @@ init: { lda #10 sta MemMap.KEYBOARD.SYS_Xmax - // CLODE TO RAM + // Clone self altering Methods to RAM MemoryClone(cloneStart, cloneEnd, $1000) rts } +// -------------------------------------------------------- +// toDebug - +// Print debug info. +// -------------------------------------------------------- toDebug: { - ModuleDefaultToDebug(module_name, version) + ModuleToDebug(module_type, module_name, version) rts } +// ======================================================== +// ////// KEYMAPPING RON ////////////////////////////////// +// ======================================================== + KeyMapVec: .word KeyMap1, KeyMap2, KeyMap3, KeyMap4 @@ -107,15 +118,32 @@ KeyMap4: .byte $FF -// ------------------------------------ -// RAM METHODS -// ------------------------------------ +// ======================================================== +// ////// METHODS RAM ///////////////////////////////////// +// ======================================================== * = * "Keyboard Ram" cloneStart: +// Code between cloneStart & cloneEnd is cloned in RAM +// at Init time. The logic alter the code itself for +// performance and so can't be executed directly in ROM. +// See .pseudopc $1000 directive below. -//------------------------------------------------------------------------------------ + +// -------------------------------------------------------- +// ReadKeyb - +// Read Keyboard input - if any- should be called in a loop +// getKey should be used after to chek if and what key was +// pressed. +// +// Example: +// loop: +// jsr Keyboard.ReadKeyb +// jsr Keyboard.GetKey +// bcs loop +// // Key here is in A +// -------------------------------------------------------- .pseudopc $1000 { ReadKeyb: lda #stringAddr // High byte - jsr Module.printVersion +// ======================================================== +// ////// MACROS ////////////////////////////////////////// +// ======================================================== + +// -------------------------------------------------------- +// ModulePrintVersion - +// Print out module version in the form of MAJ.MIN.REV. +// Exanple: 1.3.0. +// +// Parameters: +// versionPtr = Pointer to string Address +// -------------------------------------------------------- +.macro ModulePrintVersion(versionPtr) { + lda #versionPtr // High byte + jsr Module.printVersion } -.macro ModuleDefaultToDebug(module_name, version) { - PrintLine(module_name) - ModulePrintVersion(version) +// -------------------------------------------------------- +// ModulePrintType - +// Print out module Type based on Module.TYPES defs +// +// Parameters: +// versionPtr = Pointer to module type address +// -------------------------------------------------------- +.macro ModulePrintType(typePtr) { + lda typePtr + jsr Module.printType +} + +// -------------------------------------------------------- +// ModuleToDebug - +// Print out default module information. +// +// Parameters: +// moduleType = Pointer to module type address +// moduleName = Pointer to module name address +// moduleVersion = Pointer to module version address +// -------------------------------------------------------- +.macro ModuleToDebug(moduleType, moduleName, moduleVersion) { + ModulePrintType(moduleType) + lda #':' + PrintChar() + PrintLine(moduleName) + lda #$20 + PrintChar() + ModulePrintVersion(moduleVersion) PrintNewLine() } + .filenamespace Module -* = * "Module Lb" +// ======================================================== +// ////// CONSTANTS /////////////////////////////////////// +// ======================================================== -// ------------------------------------ -// METHODS -// ------------------------------------ +.namespace TYPES { + .label MAIN = 00 + .label LIB = 01 + .label PROG = 02 + .label CORE = 03 +} + +* = * "Module Lib" + +// ======================================================== +// ////// METHODS ///////////////////////////////////////// +// ======================================================== + +// -------------------------------------------------------- +// init - +// Module Init. +// -------------------------------------------------------- init: { rts } +// -------------------------------------------------------- +// toDebug - +// Print debug info. +// -------------------------------------------------------- toDebug: { - ModuleDefaultToDebug(module_name, version) + ModuleToDebug(module_type, module_name, version) rts } -//------------------------------------------------------------------------------------ +// -------------------------------------------------------- +// printVersion - +// Print out module version +// +// Parameters: +// A = Version High Pointer +// X = Version Low Pointer +// -------------------------------------------------------- printVersion: { - sta MemMap.MODULE.versionPtr - stx MemMap.MODULE.versionPtr+1 - ldy #0 - jsr printNext - lda #'.' + sta MemMap.MODULE.versionPtr + stx MemMap.MODULE.versionPtr+1 + ldy #0 + jsr printNext + lda #'.' PrintChar() - jsr printNext - lda #'.' + jsr printNext + lda #'.' PrintChar() - jsr printNext + jsr printNext rts printNext: - lda (MemMap.MODULE.versionPtr), y + lda (MemMap.MODULE.versionPtr), y clc - adc #$30 + adc #$30 PrintChar() iny rts +} +// -------------------------------------------------------- +// printType - +// Print out module type based on Module Module.TYPES +// +// Parameters: +// A = Module Type +// -------------------------------------------------------- +printType: { + cmp #Module.TYPES.MAIN + bne !+ + PrintLine(type_main) + rts + !: + cmp #Module.TYPES.LIB + bne !+ + PrintLine(type_lib) + rts + !: + cmp #Module.TYPES.CORE + bne !+ + PrintLine(type_core) + rts + !: + cmp #Module.TYPES.PROG + bne !+ + PrintLine(type_prog) + !: + rts } -// ------------------------------------ -// DATA -// ------------------------------------ +// ======================================================== +// ////// DATA //////////////////////////////////////////// +// ======================================================== * = * "Module Lib Data" -version: .byte 1, 0, 0 +module_type: .byte Module.TYPES.LIB +version: .byte 1, 1, 0 .encoding "screencode_mixed" module_name: - .text "lib:module" - .byte 0 + .text "module" + .byte 0 + +// Modile Type Names +type_main: + .text "main" + .byte 0 +type_core: + .text "core" + .byte 0 +type_lib: + .text "lib" + .byte 0 +type_prog: + .text "prog" + .byte 0 + #import "../core/mem_map.asm" diff --git a/libs/print.asm b/libs/print.asm index 1fa1d4d..c2a3ade 100644 --- a/libs/print.asm +++ b/libs/print.asm @@ -4,11 +4,11 @@ #import "../core/screen.asm" #import "../libs/module.asm" -* = * "Print Lib" -// ------------------------------------ -// MACROS -// ------------------------------------ +// ======================================================== +// ////// MACROS ////////////////////////////////////////// +// ======================================================== + .macro PrintLine(stringAddr) { lda #stringAddr // High byte @@ -25,22 +25,38 @@ .filenamespace Print -// ------------------------------------ -// METHODS -// ------------------------------------ -//------------------------------------------------------------------------------------ +* = * "Print Lib" + +// ======================================================== +// ////// METHODS ///////////////////////////////////////// +// ======================================================== + + +// -------------------------------------------------------- +// init - +// Module Init. +// -------------------------------------------------------- init: { rts } -//------------------------------------------------------------------------------------ +// -------------------------------------------------------- +// toDebug - +// Print debug info. +// -------------------------------------------------------- toDebug: { - ModuleDefaultToDebug(module_name, version) + ModuleToDebug(module_type, module_name, version) rts } -//------------------------------------------------------------------------------------ +// -------------------------------------------------------- +// printPetChar - +// Convert a Char from PET ASCII and print it out on Screen +// +// Parameters: +// A = PET ASCII char to print +// -------------------------------------------------------- printPetChar: { pha stx MemMap.SCREEN.PrintPetCharX @@ -53,15 +69,14 @@ printPetChar: { rts } -// —————————————————————————————————————————————————————— -// printLine -// —————————————————————————————————————————————————————— -// —————————————————————————————————————————————————————— -// preparatory ops: .a: low byte string address -// .x: high byte string address +// -------------------------------------------------------- +// printLine - +// Print a Null terminated SCREEN ASCII string to screen. // -// returned values: none -// —————————————————————————————————————————————————————— +// Parameters: +// A = low byte string address +// X = low byte string address +// -------------------------------------------------------- printLine: { ldy #$00 sta MemMap.SCREEN.TempStringPointer @@ -76,16 +91,17 @@ printLine: { rts } -// ———————————————————————————————————— -// btohex -// ———————————————————————————————————— -// ———————————————————————————————————— -// preparatory ops: .a: byte to convert +// -------------------------------------------------------- +// byteToHex - +// Convert a byte to an HEX value // -// returned values: .a: msn ascii char -// .x: lsn ascii char -// .y: entry value -// ———————————————————————————————————— +// Parameters: +// Y = Byte to Convert +// +// Result: +// A = msn ascii char result +// X = lns ascii char result +// -------------------------------------------------------- byteToHex: { pha //save byte and #%00001111 //extract lsn @@ -110,15 +126,16 @@ byteToHex: { rts //done } - -// ———————————————————————————————————————— -// petToScreen -// ———————————————————————————————————————— -// ———————————————————————————————————————— -// preparatory ops: .a: pet byte to convert +// -------------------------------------------------------- +// petCharToScreenChar - +// Convert a PET ASCII Char to a SCREEN ASCII Char // -// returned values: .a: conv SCREEN char -// ———————————————————————————————————————— +// Parameters: +// A = PET ASCII Byte to Convert +// +// Result: +// A = Converted ASCII SCREEN Char +// -------------------------------------------------------- petCharToScreenChar: { // $00-$1F cmp #$1f @@ -175,16 +192,18 @@ petCharToScreenChar: { } -// ------------------------------------ -// DATA -// ------------------------------------ +// ======================================================== +// ////// DATA //////////////////////////////////////////// +// ======================================================== * = * "Print Lib Data" -version: .byte 1, 0, 0 -.encoding "screencode_mixed" +module_type: .byte Module.TYPES.LIB +version: .byte 1, 0, 0 + +.encoding "screencode_mixed" module_name: - .text "lib:print" - .byte 0 + .text "print" + .byte 0 #import "../core/mem_map.asm" diff --git a/main.asm b/main.asm index 4515b1e..b8e00c9 100644 --- a/main.asm +++ b/main.asm @@ -1,6 +1,6 @@ .cpu _6502 -// BasicUpstart2(start) +//BasicUpstart2(start) #import "./core/mem_map.asm" * = $8000 "Main" diff --git a/progs/woz_shell.asm b/progs/woz_shell.asm index 62d1dce..c1b6d0f 100644 --- a/progs/woz_shell.asm +++ b/progs/woz_shell.asm @@ -1,16 +1,25 @@ #importonce -.filenamespace WozShell - #import "../libs/print.asm" #import "../libs/module.asm" #import "../core/init.asm" +.filenamespace WozShell + * = * "WozShell Routines" +// ======================================================== +// ////// CONSTANTS /////////////////////////////////////// +// ======================================================== + .const CR = $0d .const R = $52 +// ======================================================== +// ////// METHODS ///////////////////////////////////////// +// ======================================================== + + clear: init: { @@ -27,8 +36,8 @@ start: { } toDebug: { - ModuleDefaultToDebug(module_name, version) - rts + ModuleToDebug(module_type, module_name, version) + rts } push: { @@ -248,13 +257,18 @@ PRHEX: and #%00001111 // Mask LSD for hex prin } -//------------------------------------------------------------------------------------ + +// ======================================================== +// ////// DATA //////////////////////////////////////////// +// ======================================================== + * = * "WozShell Data" -version: .byte 1, 2, 0 +module_type: .byte Module.TYPES.PROG +version: .byte 1, 2, 0 .encoding "screencode_mixed" module_name: - .text "prg:woz-shell" + .text "woz-shell" .byte 0 helpString: