Introduction

The bootstrap code is a minimal routine designed to establish some common ground so that more substantial routines can be loaded in a common way. It's short enough that the assembler syntax can be converted manually. If nothing else, you can just use a DB assembler directive, or a monitor utility to enter the object code directly. The first 6 bytes and the stuff after the RTS are relocation info which can be omitted.

How to use it

To use this routine, you only need 3 consectutive zero page locations available. Use the X register to indicate which zero page locations to use. For example, to use $12, $13, and $14, enter with X = $12. The bootstrap code loads the routine at the address pointed to by 0,X (lo byte) and 1,X (hi byte). In fact, the bootstrap code only increments the low byte but not the high byte, so setting the low byte to zero (i.e. loading at a page boundary) is advised. 2,X is used only for temporary storage and does not need to be initialized. Note that the entry point is actually at the LDA #$40 instruction. The "get" routine is the input routine, which should return a character in the accumulator. You can put a JMP at address 0 or you can patch the address in the source code manually.

How it works

Characters below ASCII 33 are ignored, so the bootstrap code is somewhat fault tolerant, as spaces are ignored and line ending differences (i.e. LF vs. CR. vs. CRLF) are irrelevant. A ! character (ASCII 33) indicates the end of data. A byte whose bits are %abcdefgh is represented as two printable ASCII characters whose bits are:

This corresponds to the characters: (),-89<=hilmxy|}

Source and object code

                 [ 10 @ 'BPL'                             ]
                 [ 20 @ 'JSR'                             ]
                 [ 30 @ 'BMI'                             ]
                 [ 60 @ 'RTS'                             ]
                 [ 90 @ 'BCC'                             ]
                 [ D0 @ 'BNE'                             ]
                 [ 81 @ 'STA ,X)'                         ]
                 [ 55 @ 'EOR ,X'                          ]
                 [ 95 @ 'STA ,X'                          ]
                 [ 16 @ 'ASL ,X'                          ]
                 [ F6 @ 'INC ,X'                          ]
                 [ A9 @ 'LDA #'                           ]
                 [ C9 @ 'CMP #'                           ]
                 [                                        ]
                 [ 0000 @ 'get'                           ]
                 [                                        ]
                 [ 00 @ 'ADDRESS'                         ]
                 [ 02 @ 'BYTE'                            ]
                 [                                        ]
                 [ 1000 @                                 ]
                 [                                        ]
(10,04,         )[      'BPL',00*,                        ]
(30,02,         )[      'BMI',02*,                        ]
(18,00,         )[      (DW) 0018,, (RELDATA-PROGRAM)     ]
                 [ 00=>02=>                               ]
                 [ (PROGRAM)                              ]
(16,02,         )[ 00*  'ASL ,X','BYTE',                  ]
(55,02,         )[      'EOR ,X','BYTE',                  ]
(90,06,         )[      'BCC',02*,                        ]
(81,00,         )[      'STA ,X)','ADDRESS',              ]
(F6,00,         )[      'INC ,X','ADDRESS',               ]
(A9,40,         )[      'LDA #',40,        (entry point)  ]
(95,02,         )[ 02=> 'STA ,X','BYTE',                  ]
(20,00,00,      )[ 04*  'JSR','get',,                     ]
(C9,21,         )[      'CMP #',21,                       ]
(90,F9,         )[      'BCC',04=<                        ]
(D0,E9,         )[      'BNE',00=<                        ]
(60,            )[      'RTS',                            ]
                 [ (RELDATA)                              ]
(03,0F,00,00,00,)[      (DB) 03, (DW) 000F,, (DW) 'get',, ]
(00,            )[      (DB) 00,                          ]
(Q              )[ _                                      ]