Skip to content

Commit

Permalink
Simplify program load and start.
Browse files Browse the repository at this point in the history
Makes all the programs a few bytes smaller.
  • Loading branch information
dmsc committed Jul 27, 2024
1 parent ec333c7 commit b6c79c7
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 46 deletions.
6 changes: 2 additions & 4 deletions src/a5200cart.asm
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
; Startup and support code for the Atari 5200 port
; ------------------------------------------------

.import interpreter_run, set_grmode, bytecode_start, get_key
.import start, set_grmode, get_key
; Linker vars
.import __CART_PAL__
.import __BSS_RUN__, __BSS_SIZE__
Expand Down Expand Up @@ -178,9 +178,7 @@ copy_interpreter:
jsr set_grmode

; Starts interpreter
lda #<bytecode_start
ldx #>bytecode_start
jsr interpreter_run
jsr start

; Waits for key press
jsr get_key
Expand Down
3 changes: 0 additions & 3 deletions src/cmdmenu.asm
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
; From alloc.asm
.importzp prog_ptr
.import parser_alloc_init
; From bytecode
.import bytecode_start
.importzp NUM_VARS

; Exported to CMDLINE.BAS
BMAX=bmax
Expand Down
20 changes: 3 additions & 17 deletions src/comp_header.asm
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
; Compiled header written from the IDE
; ------------------------------------

.export start
.export BYTECODE_ADDR

.exportzp ZP_INTERP_LOAD, ZP_INTERP_SIZE

.include "atari.inc"
Expand All @@ -31,7 +29,7 @@
.import __JUMPTAB_RUN__, __RUNTIME_RUN__, __RUNTIME_SIZE__
.import __DATA_SIZE__

.import interpreter_run, bytecode_start
.import bytecode_start, start

; Interpreter locations exported as ZP to the BASIC sources
ZP_INTERP_LOAD = < __INTERP_START__
Expand All @@ -50,10 +48,10 @@ BYTECODE_ADDR= __RUNTIME_RUN__ + __RUNTIME_SIZE__ + __DATA_SIZE__
COMP_HEAD_1:
; Atari binary header
.byte 255, 255
; Chunk 1: Run address at "compiled_start"
; Chunk 1: Run address at "start"
.word RUNAD
.word RUNAD+1
.word compiled_start
.word start
; Chunk 2: interpreter at page 0
.word __INTERP_START__
.word __INTERP_START__ + __INTERP_SIZE__- 1
Expand All @@ -70,16 +68,4 @@ COMP_HEAD_2:
.export COMP_RT_SIZE
COMP_RT_SIZE = __RUNTIME_RUN__ + __RUNTIME_SIZE__ + __DATA_SIZE__ - __JUMPTAB_RUN__ + 4

; This is the runtime startup code, loads the editor.
; Note that this code is patched before writing to a file
; and copied into the resulting executables.
.segment "RUNTIME"
start:
compiled_start:
lda #<BYTECODE_ADDR
ldx #>BYTECODE_ADDR

jsr interpreter_run
jmp (DOSVEC)

; vi:syntax=asm_ca65
2 changes: 0 additions & 2 deletions src/compile.asm
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
; From alloc.asm
.importzp prog_ptr
.import parser_alloc_init
; From bytecode
.import bytecode_start

.include "atari.inc"

Expand Down
7 changes: 7 additions & 0 deletions src/interpreter.asm
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
; The opcode interpreter
; ----------------------

.export start
.export interpreter_run, stack_l, stack_h
.export pushAX, stack_end

Expand Down Expand Up @@ -139,6 +140,12 @@ move_ins = move_loop::ins

; Rest of interpreter is in runtime segment
.segment "RUNTIME"
.import bytecode_start
; Main start for a compiled program, runs the
; bytecode from the bytecode segment.
start:
lda #<bytecode_start
ldx #>bytecode_start

; Main interpreter call
; AX : address of code start
Expand Down
23 changes: 3 additions & 20 deletions src/standalone.asm
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,16 @@
; linked into a combine executable.)


; Standalone interpreter
; ----------------------
; Standalone interpreter variables
; --------------------------------

; Main symbol
.export start
; Main bytecode symbol
.exportzp array_ptr, BASIC_TOP
; From intrepreter.asm
.import interpreter_run
; From bytecode
.import bytecode_start
; Linker vars
.import __HEAP_RUN__

.include "atari.inc"

.zeropage

; Zero page variables:
array_ptr: .res 2 ; Top of array memory
BASIC_TOP= array_ptr

.code
start:
lda #<bytecode_start
ldx #>bytecode_start

jsr interpreter_run
jmp (DOSVEC)

; vi:syntax=asm_ca65

0 comments on commit b6c79c7

Please sign in to comment.