system_interface
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
system_interface [2025/07/03 14:52] – created reggie | system_interface [2025/07/03 16:11] (current) – reggie | ||
---|---|---|---|
Line 3: | Line 3: | ||
Emulated hardware is managed by writing to memory-mapped ports beginning at address $ff80. | Emulated hardware is managed by writing to memory-mapped ports beginning at address $ff80. | ||
- | const SIbaseAddress=0xff80, | + | const SIbaseAddress=$ff80 |
+ | const SIrefreshOff=0, | ||
- | SIrefreshOff | + | SIrefreshOff |
- | SIrefreshOn | + | SIrefreshOn |
- | SIgraphicsMode | + | SIgraphicsMode |
- | SIkeyInterface | + | SIkeyInterface |
| | ||
- | === Refresh === | + | ==== Refresh ==== |
- | This is a simple way of switching on or off the " | + | This is a simple way of switching on or off the " |
init: | init: | ||
clr SIbaseAddress+SIrefreshOff | clr SIbaseAddress+SIrefreshOff | ||
- | jsr ClrScrr | + | jsr ClrScr |
- | clr SIbaseAddress+SIrefreshOn | + | clr SIbaseAddress+SIrefreshOn |
+ | |||
+ | ==== Graphics Mode ==== | ||
+ | |||
+ | There are three bitmap graphics modes, differing by the resolution and colours available. | ||
+ | |||
+ | 2 colours, 1 bit per pixel | ||
+ | 4 colours, 2 bits per pixel | ||
+ | 16 colours, 4 bits per pixel | ||
+ | |||
+ | To select a mode, simply write the number of colours to SIbaseAddress+SIgraphicsMode | ||
+ | |||
+ | Select16ColMode: | ||
+ | lda #16 | ||
+ | sta SIbaseAddress+SIgraphicsMode | ||
+ | |||
+ | The emulator' | ||
+ | |||
+ | Select4ColMode: | ||
+ | lda #$02 ; A=service number 2 (graphics mode) | ||
+ | ldb #$04 ; B=argument (4 colour mode) | ||
+ | swi3 | ||
+ | |||
+ | Now all writes to the graphics display area will be interpreted in this mode. Note that to save time this does NOT effect anything already on the display until the memory is read or written. So you may need to clear the screen after selecting the mode. | ||
+ | |||
+ | === Graphics Screen Layout === | ||
+ | |||
+ | In all modes the graphics RAM beings at $0600 and is 6K bytes long. In 2 colour mode it is 256 pixels wide by 192 pixels high. It is conventional to map the display with the top-left at (0,0) and the bottom right at (255,191) using the same virtual coordinates whatever the colour mode. Therefore in 4-colour mode pixels are 2*1 units in size, and in 16-colour mode 2*2 units. | ||
+ | |||
+ | const grxBase=$0600, | ||
+ | |||
+ | Using 2-colour mode as an example, memory layout is from screen left to right, then top to bottom. So pixels (0,0) to (7,0) are stored in the byte at offset 0. The most significant bit in the byte represents the leftmost pixel. To represent a row of 256 pixels takes 32 bytes. So we add 32 bytes to the base address for each row moved down, thus pixel (0,1) is stored in the byte at offset 32. | ||
+ | |||
+ | The 4-colour mode needs 2 bits for each pixel, thus to store pixels of colours of successively 0, 1, 2, 3 at coordinates (0,0), (2,0), (4,0), (6,0) would mean storing the binary value 00011011 at byte offset 0. | ||
+ | |||
+ | The 16-colour mode needs 4 bits per pixel, with 128 pixels (hence 64 bytes) per line, with only 96 lines. Thus to store colours 4 and 13 at coordinates (128,160) and (130,160) would mean storing the binary value 01001101 at byte offset $1420. | ||
+ | |||
+ | === Palette === | ||
+ | |||
+ | The colour palette used is the 16-colour [[https:// | ||
+ | |||
+ | ==== Keyboard ==== | ||
+ | |||
+ | The keyboard is accessed by a single port. Simply write 0 to the port then read from the same address. A negative value means no key has been pressed, otherwise the value is the ASCII code of the last key pressed. Write $ff to the same port to clear the keyboard buffer. | ||
+ | |||
+ | ; Read an ASCII character from the keyboard | ||
+ | readChr: | ||
+ | clra | ||
+ | sta SIBaseAddress+SIKeyInterface | ||
+ | lda SIBaseAddress+SIKeyInterface | ||
+ | bmi readChr | ||
+ | cmpa # | ||
+ | rts | ||
+ | |||
+ | |||
system_interface.1751554371.txt.gz · Last modified: 2025/07/03 14:52 by reggie