Filling the screen with colors in c and assembler (Pasmo, z88dk and sdcc) Pincha aquí para verlo en español The Amstrad CPC has three video modes : "Mode 0" 160×200 pixels with 16 colors, "Mode 1" 320×200 pixels with 4 colors and "Mode 2" 640×200 pixels with 2 colors. The video memory is located between the addresses C000 to FFFF, ie has a size of 3FFF (16,383) bytes. Depending on the mode, each byte represents 2, 4 or 8 pixels of the screen. In this example, we'll just fill the entire screen with the same value 256 times (with values from 0 to 255), so you will see the screen changing color quickly, the program will work in mode 0, to have 16 colors. At the end of this tutorial you can download a zip with all files. Source code for z88dk: #include <strings.h> main() { unsigned char nColor = 0; //set mode 0 #asm ld a,0 call $BC0E #endasm for(nColor = 0; nColor < 255; nColor++) { memset(0xC000, nColor, 0x3FFF); } //wait char #asm call $BB06 #endasm }
Source code for sdcc: #include <string.h> void main() { unsigned char nColor = 0; //set mode 0 __asm ld a, #0 call #0xBC0E __endasm; for(nColor = 0; nColor < 255; nColor++) { memset(0xC000, nColor, 0x3FFF); } __asm call #0xBB06 __endasm; }
Source code in assembler: org #6000 KM_WAIT_CHAR EQU #BB06 ;set mode 0 ld a, 0 call #BC0E ;from 0 to 255 ld d,#00 startloop: ld a, d sub #FF jr NC,endloop ld e,d push de ;memset ld hl,#C000 ld (hl), e ld e, l ld d, h inc de ld bc, #3FFF ldir pop de inc d jr startloop endloop: CALL KM_WAIT_CHAR RET |
You should see something like this: The three binaries have the same speed (as they use to fill ldir), but curiously the binary generated by z88dk occupies 193 bytes, the generated by sdcc occupies 93 bytes and the generated by Pasmo occupies 34 bytes. You can download a zip with all files here : Filling_the_screen_with_colors_in_c_and_assembler_Pasmo_z88dk_sdcc.zip |
www.CPCMania.com 2012 |