sd:a_guide_to_graphics_programming_on_the_sd-8516
Differences
This shows you the differences between two versions of the page.
| sd:a_guide_to_graphics_programming_on_the_sd-8516 [2026/04/27 18:22] – created appledog | sd:a_guide_to_graphics_programming_on_the_sd-8516 [2026/04/27 18:50] (current) – appledog | ||
|---|---|---|---|
| Line 7: | Line 7: | ||
| For BASIC programmers, | For BASIC programmers, | ||
| + | Before we begin, let's introduce some key concepts about graphics programming on the SD-8516, such as the various Modes, the Framebuffer, | ||
| - | == Graphics Modes | + | === Graphics Modes |
| The text modes do not have graphics ability. They are solely used for representing text, so we won't discuss them here. | The text modes do not have graphics ability. They are solely used for representing text, so we won't discuss them here. | ||
| Line 24: | Line 25: | ||
| Almost everything that is discussed here will be applicable to all graphics modes. So, we will use Mode 3 as an example and note anything you need to watch out for in other modes. | Almost everything that is discussed here will be applicable to all graphics modes. So, we will use Mode 3 as an example and note anything you need to watch out for in other modes. | ||
| - | == The Framebuffer | + | === The Framebuffer |
| The SD-8516 uses a memory-mapped framebuffer. To render a frame, the Video Chip scans the framebuffer' | The SD-8516 uses a memory-mapped framebuffer. To render a frame, the Video Chip scans the framebuffer' | ||
| Line 41: | Line 42: | ||
| This sets the low nibble to 1 and the high nibble to 2. Remember, $21 is a hexidecimal number; each place in hex is 4 bits. | This sets the low nibble to 1 and the high nibble to 2. Remember, $21 is a hexidecimal number; each place in hex is 4 bits. | ||
| - | === Memory Map | + | ==== Framebuffer |
| The framebuffer for mode 3 is stored in the first 32kb of Bank 2. Some modes, such as mode 5 and 7 use almost all of bank 2. Mode 9 uses both bank 2 and bank 3. Memory which isn't being used can be used by your programs; so if you're using Mode 3, you can store data in the second half of bank 2. | The framebuffer for mode 3 is stored in the first 32kb of Bank 2. Some modes, such as mode 5 and 7 use almost all of bank 2. Mode 9 uses both bank 2 and bank 3. Memory which isn't being used can be used by your programs; so if you're using Mode 3, you can store data in the second half of bank 2. | ||
| - | == Reading and Writing Pixels | + | ==== Accessing the Framebuffer |
| For BASIC, you can PEEK and POKE at framebuffer memory or use the PIXEL/PEXEL commands: | For BASIC, you can PEEK and POKE at framebuffer memory or use the PIXEL/PEXEL commands: | ||
| Line 53: | Line 54: | ||
| This program reads a pixel and updates it's color. | This program reads a pixel and updates it's color. | ||
| - | === Packing and Unpacking pixels | + | ==== Packing and Unpacking pixels |
| For Assembly and other languages, you will need to pack and unpack the pixel. In Assembly you can use PAB and UAB, but in Forth or other languages you must mask the byte (and do a bit shift for the upper nibble). | For Assembly and other languages, you will need to pack and unpack the pixel. In Assembly you can use PAB and UAB, but in Forth or other languages you must mask the byte (and do a bit shift for the upper nibble). | ||
| Line 89: | Line 90: | ||
| For 8bpp modes you don't need to worry about this at all. The byte is the pixel. | For 8bpp modes you don't need to worry about this at all. The byte is the pixel. | ||
| + | |||
| + | ==== The Three Main Systems | ||
| + | The SD-8516 has a PPU (picture processing unit) which aids in graphics programming. This is the fastest way to do graphics programming. Stellar BASIC uses the PPU to accelerate graphics performance, | ||
| + | |||
| + | For Assembly programmers, | ||
| + | |||
| + | The PPU is the second system. The PPU is accessed via INT 0x03 AH = $01. The subcommand is in AL. We will discuss each command and their calling conventions in the sections below. | ||
| + | |||
| + | The third system is a direct call to the PPU via an opcode. This is just like how the FPU works on older 80x86 systems; or how cartridges can add extra opcodes. The opcode instructions and their calling conventions will be discussed in the sections below. | ||
| + | |||
| + | == 1. Clearing the Screen | ||
| + | Clearing the screen is a good way to ensure a default initial state for a program. | ||
| + | |||
| + | In BASIC, the CLS command will clear the screen of the mode you are in. | ||
| + | |||
| + | For Assembly, INT 18h, AH=20h will clear the screen in a graphics mode. | ||
| + | |||
| + | LDAH $20 ; Clear Screen | ||
| + | INT 0x18 | ||
| + | |||
| + | You can also use the PPU to do this. This way is very fast. | ||
| + | |||
| + | LDA $0100 ; AH=$01 (PPU) AL=$00 (Clear Screen) | ||
| + | INT 0x03 | ||
| + | |||
| + | == 2. Drawing (and reading) a Pixel | ||
| + | We've discussed how to do this in BASIC and Assembly above under " | ||
| + | |||
| + | However, Assembly programmers will be pleased to know the PPU calls for this. | ||
| + | |||
| + | LDA $0101 ; AH=$01 (PPU) AL=$01 (plot_pixel) | ||
| + | INT 0x03 | ||
| + | |||
| + | or | ||
| + | |||
| + | PPIXEL | ||
| + | |||
| + | PPIXEL is not faster than calling INT $3, however, you don't have to LDA $0100 and that can save time. In a loop where LDA can remain $0101 they are approximately as fast as each other. | ||
| + | |||
| + | The calling convention is X, Y, CK for X position, Y position, and pixel color. The PPU is mode-aware, so it will automatically do 4bpp pixel conversion for you. | ||
| + | |||
| + | To read from a pixel quickly you can load it from the framebuffer, | ||
| + | |||
| + | LDA $0102 ; AH=$01 (PPU) AL=$02 (read_pixel) | ||
| + | INT 0x03 | ||
| + | |||
| + | The color will be returned in CL. | ||
| + | |||
| + | == 3. Drawing a Line | ||
| + | In BASIC, you can use the LINE command: | ||
| + | |||
| + | LINE x1, y1, x2, y2, color | ||
| + | |||
| + | Assembly has AH=$12 INT 0x18: | ||
| + | |||
| + | ; ============================================================================ | ||
| + | ; AH=21h - Draw Line (Bresenham' | ||
| + | ; Input: | ||
| + | ; I = x1, J = y1 (end point) | ||
| + | ; CL = color | ||
| + | ; Output: None | ||
| + | ; ============================================================================ | ||
| + | |||
| + | However, the fastest way to draw a line is with the PPU. The calling convention is to draw a line from X,Y to I,J in color CL. | ||
| + | |||
| + | LDA $0103 ; AH=$01 (PPU) AL=$03 (draw_line) | ||
| + | INT 0x03 | ||
| + | |||
| + | you can also use PLINE: | ||
| + | |||
| + | PLINE | ||
| + | |||
| + | PLINE is like PPIXEL, it's sometimes faster to use PPIXEL than make a call to INT 0x03. | ||
| + | |||
| + | |||
| + | //under construction// | ||
| + | |||
| + | FIXME | ||
sd/a_guide_to_graphics_programming_on_the_sd-8516.txt · Last modified: by appledog
