Commit MetaInfo

Revisionbe9593040a6fb01b4a8d489a3835bac9d1a9cef4 (tree)
Time2019-02-02 16:04:12
Authoringlorion <homemicro@ingl...>
Commiteringlorion

Log Message

include sample program in programming guide

Change Summary

Incremental Difference

diff -r 5346c5a13459 -r be9593040a6f docs/programming.txt
--- a/docs/programming.txt Fri Feb 01 22:24:01 2019 -0800
+++ b/docs/programming.txt Fri Feb 01 23:04:12 2019 -0800
@@ -1,29 +1,63 @@
11 #+TITLE: Home Micro Programmer's Manual
22
3-* Register and Memory Usage
4-
5- - Freely available to user programs:
6- - $00 through $7f.
7- - $300 through $17ff.
8- - $4000 through $57ff.
9- - $8000 through $bfff.
10-
11- - Available, but not preserved by ROM procedures:
12- - Registers a, x, and y.
13- - Memory locations $a0 through $af.
3+* 6502 Assembly
144
15- - Available when not used for video (see [Video Modes] for details):
16- - $1800 through $3fff.
17- - $5800 through $7fff.
5+The Home Micro uses a MOS Technology 6502 or compatible CPU. To
6+generate code for the CPU to execute, programs are written in 6502
7+assembly language and translated to machine code using an assembler.
188
19- - Reserved memory ranges:
20- - $80 through $9f.
21- - $b0 through $ff.
22- - $200 through $2ff.
23- - $c000 through $dfff.
9+A tutorial on 6502 assembly language can be found at
10+http://obelisk.me.uk/6502/index.html
2411
25- - ROM:
26- - $e000 through $ffff.
12+To convert human-readable assembly language programs into binary
13+code the computer can run, we use an assembler. Programs in the
14+Home Micro repository have been tested with the freely available
15+assembler xa. This assembler can be installed on Raspbian using
16+
17+: sudo aptitude install xa65
18+
19+* Simple Program
20+
21+Here is a simple program for the Home Micro 1000:
22+
23+#+BEGIN_SRC
24+ pagesize = 32
25+ cls = $e003
26+
27+ * = $0000
28+ .byt "HM",0,1
29+ .word _start
30+ .word pagesize
31+ .word _endhdr
32+ .word _end-_start
33+ .word _start
34+ .word 0
35+_endhdr:
36+ * = $0300
37+_start:
38+ jsr cls
39+ lda #$a0
40+ sta $2000
41+ lda #$05
42+ sta $2001
43+_halt:
44+ jmp _halt
45+_end:
46+#+END_SRC
47+
48+The first few lines of the code define a number of constants. This
49+way, we can use the names in the code, instead of the numeric values.
50+This makes the code easier to read and modify.
51+
52+The next part is the program header. It describes how to load and run
53+the program and is discussed in more detail in the [[Program Header]]
54+chapter.
55+
56+The part of the program that actually does things is after the
57+_start label. It first calls the procedure ~cls~, which clears the
58+screen. It then writes a few bytes to the beginning of video memory,
59+causing some dot patterns to appear. Finally, it enters an
60+infinite loop, repeatedly jumping to the _halt label.
2761
2862 * Program Header
2963
@@ -61,6 +95,32 @@
6195 would also store 32 ($0020) in the variable that holds the cartridge
6296 page size. This value is used when writing to the cartridge.
6397
98+
99+* Register and Memory Usage
100+
101+ - Freely available to user programs:
102+ - $00 through $7f.
103+ - $300 through $17ff.
104+ - $4000 through $57ff.
105+ - $8000 through $bfff.
106+
107+ - Available, but not preserved by ROM procedures:
108+ - Registers a, x, and y.
109+ - Memory locations $a0 through $af.
110+
111+ - Available when not used for video (see [Video Modes] for details):
112+ - $1800 through $3fff.
113+ - $5800 through $7fff.
114+
115+ - Reserved memory ranges:
116+ - $80 through $9f.
117+ - $b0 through $ff.
118+ - $200 through $2ff.
119+ - $c000 through $dfff.
120+
121+ - ROM:
122+ - $e000 through $ffff.
123+
64124 * Video Modes
65125
66126 | Mode | Bit/Char | Pixels | Colors | Tiles |
Show on old repository browser