Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commit26f47ec8631e796e1cab4361ba057292a72c1d0f (patch)
Author
 Syndamia <kamen@syndamia.com>
2025-07-31 00:41:09 +0300
Committer
 Syndamia <kamen@syndamia.com>
2025-07-31 00:41:09 +0300
Files86680b6522e4939291ad1f64686fdf2033d40e3f
c64-programs-26f47ec8631e796e1cab4361ba057292a72c1d0f.tar
c64-programs-26f47ec8631e796e1cab4361ba057292a72c1d0f.tar.gz
c64-programs-26f47ec8631e796e1cab4361ba057292a72c1d0f.zip
Parentbc8ec38d870f65aae5bb53b9dd1a8f18ddff8708 (diff)
feat(hello_world): Split hello.oph into multiple files
4 files changed, 48 insertions, 47 deletions
-rw-r--r--hello_world/Makefile2
-rw-r--r--hello_world/basic_starter.oph28
-rw-r--r--hello_world/hello.oph53
-rw-r--r--hello_world/kernal.oph12
diff --git a/hello_world/Makefile b/hello_world/Makefile
index 7bec999..016291a 100644
--- a/hello_world/Makefile
+++ b/hello_world/Makefile
@@ -4,7 +4,7 @@ VICEFLAGS=-VICIIfilter 0
.PHONY: build execute run
build:
- ophis *.oph
+ ophis hello.oph
execute:
$(VICE) $(VICEFLAGS) *.prg >/dev/null
diff --git a/hello_world/basic_starter.oph b/hello_world/basic_starter.oph
new file mode 100644
index 0000000..b893c08
--- /dev/null
+++ b/hello_world/basic_starter.oph
@@ -0,0 +1,28 @@
+; PRG format
+; Contains two bytes of header data, address from which
+; the rest of the file will be loaded into memory.
+; BASIC memory starts at addr 2048, we effectively place "10 SYS 2064"
+; and an end of program after it. Then immedately afterwards
+; we place our command on addr 2064.
+; When BASIC loads up, it runs "10 SYS 2064" and passes up execution there.
+; Then, when we return, we get a zero which indicates termination.
+
+; The starting address is defined by the value (label or alias) "main".
+; Since in basic we need to provide a decimal string, but we store a decimal value, we need
+; to do this complicated convertion.
+.alias main_addr_ch1 '0 + main / 10000 ; 65535 -> 6
+.alias main_addr_ch2 '0 + [main - main / 10000 * 10000] / 1000 ; 65535 -> 65535 - 60000 = 5535 / 1000 = 5
+.alias main_addr_ch3 '0 + [main - main / 1000 * 1000] / 100 ; 65535 -> 65535 - 65000 = 535 / 100 = 5
+.alias main_addr_ch4 '0 + [main - main / 100 * 100] / 10 ; 65535 -> 65535 - 65500 = 35 / 10 = 3
+.alias main_addr_ch5 '0 + main - main / 10 * 10 ; 65535 -> 65535 - 65530 = 5
+
+.word $0801 ; Header -- addr 2049
+.org $0801 ; Program Counter
+
+.scope
+ .word _eop ; Next line addr (I guess it is used to tell how long the line is?)
+ .word 10 ; 10 (line of BASIC program)
+ .byte $9e," " ; SYS 2064 (opcode for SYS and null terminated string)
+ .byte main_addr_ch1,main_addr_ch2,main_addr_ch3,main_addr_ch4,main_addr_ch5,0
+_eop: .word 0 ; End of program
+.scend
diff --git a/hello_world/hello.oph b/hello_world/hello.oph
index eac7786..7314301 100644
--- a/hello_world/hello.oph
+++ b/hello_world/hello.oph
@@ -1,13 +1,9 @@
-; The 6502 is little endian! (4 3 2 1)
+; Many thanks to:
+; https://michaelcmartin.github.io/Ophis/
+; https://www.nesdev.org/obelisk-6502-guide/addressing.html
+; https://www.masswerk.at/6502/6502_instruction_set.html
-; PRG format
-; Contains two bytes of header data, address from which
-; the rest of the file will be loaded into memory.
-; BASIC memory starts at addr 2048, we effectively place "10 SYS 2064"
-; and an end of program after it. Then immedately afterwards
-; we place our command on addr 2064.
-; When BASIC loads up, it runs "10 SYS 2064" and passes up execution there.
-; Then, when we return, we get a zero which indicates termination.
+; The 6502 is little endian! (4 3 2 1)
; lables
; [a-z]: Normal label
@@ -72,43 +68,8 @@
.outfile "hello.prg"
-;== Preloader ==;
-
-; The starting address is defined by the value (label or alias) "main".
-; Since in basic we need to provide a decimal string, but we store a decimal value, we need
-; to do this complicated convertion.
-.alias main_addr_ch1 '0 + main / 10000 ; 65535 -> 6
-.alias main_addr_ch2 '0 + [main - main / 10000 * 10000] / 1000 ; 65535 -> 65535 - 60000 = 5535 / 1000 = 5
-.alias main_addr_ch3 '0 + [main - main / 1000 * 1000] / 100 ; 65535 -> 65535 - 65000 = 535 / 100 = 5
-.alias main_addr_ch4 '0 + [main - main / 100 * 100] / 10 ; 65535 -> 65535 - 65500 = 35 / 10 = 3
-.alias main_addr_ch5 '0 + main - main / 10 * 10 ; 65535 -> 65535 - 65530 = 5
-
-.word $0801 ; Header -- addr 2049
-.org $0801 ; Program Counter
-
-.scope
- .word _eop ; Next line addr (I guess it is used to tell how long the line is?)
- .word 10 ; 10 (line of BASIC program)
- .byte $9e," " ; SYS 2064 (opcode for SYS and null terminated string)
- .byte main_addr_ch1,main_addr_ch2,main_addr_ch3,main_addr_ch4,main_addr_ch5,0
-_eop: .word 0 ; End of program
-.scend
-
-;== Program ==;
-
-; KERNAL
-.alias putchar $FFD2
-
-; PROGRAM
-.macro print
- ldx #0 ; x = 0
- _loop: lda _1, x ; while (_1[x] != 0) {
- beq _done
- jsr putchar ; putchar(_1[x])
- inx ; ++x
- jmp _loop ; }
- _done:
-.macend
+.require "basic_starter.oph"
+.require "kernal.oph"
main: `print hello
rts
diff --git a/hello_world/kernal.oph b/hello_world/kernal.oph
new file mode 100644
index 0000000..086d3c1
--- /dev/null
+++ b/hello_world/kernal.oph
@@ -0,0 +1,12 @@
+.alias putchar $FFD2
+
+; print [null-terminated string start address]
+.macro print
+ ldx #0 ; x = 0
+ _loop: lda _1, x ; while (_1[x] != 0) {
+ beq _done
+ jsr putchar ; putchar(_1[x])
+ inx ; ++x
+ jmp _loop ; }
+ _done:
+.macend