| 35 | 35 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,162 @@ |
| 1 |
+( draw routines ) |
|
| 2 |
+ |
|
| 3 |
+%RTN { JMP2r }
|
|
| 4 |
+%++ { #0001 ADD2 }
|
|
| 5 |
+%8+ { #0008 ADD2 }
|
|
| 6 |
+ |
|
| 7 |
+;color { byte 1 }
|
|
| 8 |
+;pointer { x 2 y 2 sprite 2 }
|
|
| 9 |
+;rect { x1 2 y1 2 x2 2 y2 2 }
|
|
| 10 |
+;r1 { x1 2 y1 2 x2 2 y2 2 }
|
|
| 11 |
+;r2 { x1 2 y1 2 x2 2 y2 2 }
|
|
| 12 |
+;r3 { x1 2 y1 2 x2 2 y2 2 }
|
|
| 13 |
+;window { x1 2 y1 2 x2 2 y2 2 w 2 h 2 }
|
|
| 14 |
+;label { x 2 y 2 addr 2 }
|
|
| 15 |
+ |
|
| 16 |
+|0110 ;Screen { width 2 height 2 pad 4 x 2 y 2 color 1 }
|
|
| 17 |
+|0120 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 }
|
|
| 18 |
+|0150 ;Mouse { x 2 y 2 state 1 chord 1 }
|
|
| 19 |
+ |
|
| 20 |
+|01F0 .RESET .FRAME .ERROR ( vectors ) |
|
| 21 |
+|01F8 [ f07c f0e2 f0c2 ] ( palette ) |
|
| 22 |
+ |
|
| 23 |
+|0200 @RESET |
|
| 24 |
+ |
|
| 25 |
+ #0080 =window.w |
|
| 26 |
+ #0050 =window.h |
|
| 27 |
+ |
|
| 28 |
+ ( center window ) |
|
| 29 |
+ |
|
| 30 |
+ ~Screen.width #0002 DIV2 ~window.w #0002 DIV2 SUB2 =window.x1 |
|
| 31 |
+ ~Screen.height #0002 DIV2 ~window.h #0002 DIV2 SUB2 =window.y1 |
|
| 32 |
+ |
|
| 33 |
+ ,draw-window JSR2 |
|
| 34 |
+ |
|
| 35 |
+BRK |
|
| 36 |
+ |
|
| 37 |
+@FRAME |
|
| 38 |
+ |
|
| 39 |
+ ,draw-cursor JSR2 |
|
| 40 |
+ |
|
| 41 |
+BRK |
|
| 42 |
+ |
|
| 43 |
+@draw-window |
|
| 44 |
+ |
|
| 45 |
+ ~window.x1 ~window.w ADD2 =window.x2 |
|
| 46 |
+ ~window.y1 ~window.h ADD2 =window.y2 |
|
| 47 |
+ ~window.x1 ~window.y1 ~window.x2 ~window.y2 #02 ,fill-rect JSR2 |
|
| 48 |
+ ~window.x1 ~window.y1 ~window.x2 ~window.y2 #01 ,line-rect JSR2 |
|
| 49 |
+ ~window.x1 #0002 SUB2 ~window.y1 #0002 SUB2 ~window.x2 #0002 ADD2 ~window.y2 #0002 ADD2 #01 ,line-rect JSR2 |
|
| 50 |
+ ~window.x1 ~window.y1 #04 ,window_txt ,draw-label JSR2 |
|
| 51 |
+ ~window.x1 #0008 ADD2 ~window.y1 #0010 ADD2 #05 ,red_txt ,draw-label JSR2 |
|
| 52 |
+ ~window.x1 #0008 ADD2 ~window.y1 #0020 ADD2 #05 ,green_txt ,draw-label JSR2 |
|
| 53 |
+ ~window.x1 #0008 ADD2 ~window.y1 #0030 ADD2 #05 ,blue_txt ,draw-label JSR2 |
|
| 54 |
+ |
|
| 55 |
+RTN |
|
| 56 |
+ |
|
| 57 |
+@draw-cursor |
|
| 58 |
+ |
|
| 59 |
+ ( clear last cursor ) |
|
| 60 |
+ ,clear_icn =Sprite.addr |
|
| 61 |
+ ~pointer.x =Sprite.x |
|
| 62 |
+ ~pointer.y =Sprite.y |
|
| 63 |
+ #10 =Sprite.color |
|
| 64 |
+ |
|
| 65 |
+ ( record pointer positions ) |
|
| 66 |
+ ~Mouse.x =pointer.x ~Mouse.y =pointer.y |
|
| 67 |
+ |
|
| 68 |
+ ( draw new cursor ) |
|
| 69 |
+ ,pointer_icn =Sprite.addr |
|
| 70 |
+ ~pointer.x =Sprite.x |
|
| 71 |
+ ~pointer.y =Sprite.y |
|
| 72 |
+ #11 =Sprite.color |
|
| 73 |
+ |
|
| 74 |
+RTN |
|
| 75 |
+ |
|
| 76 |
+@fill-rect ( x1 y1 x2 y2 color ) |
|
| 77 |
+ |
|
| 78 |
+ ( load ) =color =rect.y2 =rect.x2 DUP2 =Screen.y =rect.y1 DUP2 =Screen.x =rect.x1 |
|
| 79 |
+ $ver |
|
| 80 |
+ ~rect.x1 =Screen.x |
|
| 81 |
+ $hor |
|
| 82 |
+ ( draw ) ~color =Screen.color |
|
| 83 |
+ ( incr ) ~Screen.x ++ =Screen.x |
|
| 84 |
+ ,$hor ~Screen.x ~rect.x2 LTH2 JMP2? |
|
| 85 |
+ ( incr ) ~Screen.y ++ =Screen.y |
|
| 86 |
+ ,$ver ~Screen.y ~rect.y2 LTH2 JMP2? |
|
| 87 |
+ |
|
| 88 |
+RTN |
|
| 89 |
+ |
|
| 90 |
+@line-rect ( x1 y1 x2 y2 color ) |
|
| 91 |
+ |
|
| 92 |
+ ( load ) =color =rect.y2 =rect.x2 DUP2 =Screen.y =rect.y1 DUP2 =Screen.x =rect.x1 |
|
| 93 |
+ $hor |
|
| 94 |
+ ( incr ) ~Screen.x ++ =Screen.x |
|
| 95 |
+ ( draw ) ~rect.y1 =Screen.y ~color =Screen.color |
|
| 96 |
+ ( draw ) ~rect.y2 =Screen.y ~color =Screen.color |
|
| 97 |
+ ,$hor ~Screen.x ~rect.x2 LTH2 JMP2? |
|
| 98 |
+ ~rect.y1 =Screen.y |
|
| 99 |
+ $ver |
|
| 100 |
+ ( draw ) ~rect.x1 =Screen.x ~color =Screen.color |
|
| 101 |
+ ( draw ) ~rect.x2 =Screen.x ~color =Screen.color |
|
| 102 |
+ ( incr ) ~Screen.y ++ =Screen.y |
|
| 103 |
+ ,$ver ~Screen.y ~rect.y2 ++ LTH2 JMP2? |
|
| 104 |
+ |
|
| 105 |
+RTN |
|
| 106 |
+ |
|
| 107 |
+@draw-label ( x y color addr ) |
|
| 108 |
+ |
|
| 109 |
+ ( load ) =label.addr =color =Sprite.y =Sprite.x ~label.addr |
|
| 110 |
+ $loop |
|
| 111 |
+ ( draw ) DUP2 LDR #00 SWP #0008 MUL2 ,font ADD2 =Sprite.addr ~color =Sprite.color |
|
| 112 |
+ ( incr ) ++ |
|
| 113 |
+ ( incr ) ~Sprite.x 8+ =Sprite.x |
|
| 114 |
+ DUP2 LDR #00 NEQ ,$loop ROT JMP2? |
|
| 115 |
+ POP2 |
|
| 116 |
+ |
|
| 117 |
+RTN |
|
| 118 |
+ |
|
| 119 |
+@clear_icn [ 0000 0000 0000 0000 ] |
|
| 120 |
+@pointer_icn [ 80c0 e0f0 f8e0 1000 ] |
|
| 121 |
+@window_txt [ theme 20 editor 00 ] |
|
| 122 |
+@red_txt [ red 00 ] |
|
| 123 |
+@green_txt [ green 00 ] |
|
| 124 |
+@blue_txt [ blue 00 ] |
|
| 125 |
+ |
|
| 126 |
+@font ( spectrum-zx font ) |
|
| 127 |
+[ |
|
| 128 |
+ 0000 0000 0000 0000 0000 2400 7e3c 0000 0000 2400 3c42 0000 0000 6c7c 7c38 1000 |
|
| 129 |
+ 0010 387c 7c38 1000 0038 387c 6c10 3800 0010 387c 7c10 3800 0000 0018 1800 0000 |
|
| 130 |
+ 007e 4242 4242 7e00 0000 1824 2418 0000 0018 2442 4224 1800 001e 063a 4a48 3000 |
|
| 131 |
+ 0038 446c 107c 1000 000c 0808 0838 3800 003e 2222 2266 6600 0000 0822 0022 0800 |
|
| 132 |
+ 0000 1018 1c18 1000 0000 0818 3818 0800 0008 1c00 001c 0800 0028 2828 2800 2800 |
|
| 133 |
+ 003e 4a4a 3a0a 0a00 000c 3046 620c 3000 0000 0000 0000 ffff 0010 3800 3810 0038 |
|
| 134 |
+ 0008 1c2a 0808 0800 0008 0808 2a1c 0800 0000 0804 7e04 0800 0000 1020 7e20 1000 |
|
| 135 |
+ 0000 4040 7e00 0000 0000 0024 6624 0000 0000 1038 7c00 0000 0000 007c 3810 0000 |
|
| 136 |
+ 0000 0000 0000 0000 0008 0808 0800 0800 0014 1400 0000 0000 0024 7e24 247e 2400 |
|
| 137 |
+ 0008 1e28 1c0a 3c08 0042 0408 1020 4200 0030 4832 4c44 3a00 0008 1000 0000 0000 |
|
| 138 |
+ 0004 0808 0808 0400 0010 0808 0808 1000 0000 1408 3e08 1400 0000 0808 3e08 0800 |
|
| 139 |
+ 0000 0000 0008 0810 0000 0000 3c00 0000 0000 0000 0000 0800 0000 0204 0810 2000 |
|
| 140 |
+ 003c 464a 5262 3c00 0018 2808 0808 3e00 003c 4202 3c40 7e00 003c 421c 0242 3c00 |
|
| 141 |
+ 0008 1828 487e 0800 007e 407c 0242 3c00 003c 407c 4242 3c00 007e 0204 0810 1000 |
|
| 142 |
+ 003c 423c 4242 3c00 003c 4242 3e02 3c00 0000 0008 0000 0800 0000 0800 0008 0810 |
|
| 143 |
+ 0000 0810 2010 0800 0000 003e 003e 0000 0000 1008 0408 1000 003c 4202 0c00 0800 |
|
| 144 |
+ 003c 425a 5442 3c00 0018 2442 7e42 4200 007c 427c 4242 7c00 003c 4240 4042 3c00 |
|
| 145 |
+ 0078 4442 4244 7800 007e 407c 4040 7e00 003e 4040 7c40 4000 003c 4240 4e42 3c00 |
|
| 146 |
+ 0042 427e 4242 4200 003e 0808 0808 3e00 0002 0202 4242 3c00 0044 4870 4844 4200 |
|
| 147 |
+ 0040 4040 4040 7e00 0042 665a 4242 4200 0042 6252 4a46 4200 003c 4242 4242 3c00 |
|
| 148 |
+ 007c 4242 7c40 4000 003c 4242 524a 3c00 007c 4242 7c44 4200 003c 403c 0242 3c00 |
|
| 149 |
+ 00fe 1010 1010 1000 0042 4242 4242 3c00 0042 4242 4224 1800 0042 4242 5a66 4200 |
|
| 150 |
+ 0042 2418 1824 4200 0082 4428 1010 1000 007e 0408 1020 7e00 000c 0808 0808 0c00 |
|
| 151 |
+ 0040 2010 0804 0200 0018 0808 0808 1800 0008 1422 0000 0000 0000 0000 0000 7e00 |
|
| 152 |
+ 0008 0400 0000 0000 0000 1c02 1e22 1e00 0020 203c 2222 3c00 0000 1e20 2020 1e00 |
|
| 153 |
+ 0002 021e 2222 1e00 0000 1c22 3c20 1e00 000c 101c 1010 1000 0000 1c22 221e 021c |
|
| 154 |
+ 0020 202c 3222 2200 0008 0018 0808 0400 0008 0008 0808 4830 0020 2428 3028 2400 |
|
| 155 |
+ 0010 1010 1010 0c00 0000 6854 5454 5400 0000 5864 4444 4400 0000 3844 4444 3800 |
|
| 156 |
+ 0000 7844 4478 4040 0000 3c44 443c 0406 0000 2c30 2020 2000 0000 3840 3804 7800 |
|
| 157 |
+ 0010 103c 1010 0c00 0000 4444 4444 3800 0000 4444 2828 1000 0000 4454 5454 2800 |
|
| 158 |
+ 0000 4428 1028 4400 0000 4444 443c 0438 0000 7c08 1020 7c00 000c 0810 1008 0c00 |
|
| 159 |
+ 0008 0808 0808 0800 0030 1008 0810 3000 0000 0032 4c00 0000 3c42 99a1 a199 423c |
|
| 160 |
+] |
|
| 161 |
+ |
|
| 162 |
+@ERROR BRK |
| ... | ... |
@@ -20,27 +20,17 @@ WITH REGARD TO THIS SOFTWARE. |
| 20 | 20 |
#define RES (HOR * VER * 16) |
| 21 | 21 |
|
| 22 | 22 |
typedef struct {
|
| 23 |
+ Uint8 reqdraw, bg[RES], fg[RES]; |
|
| 23 | 24 |
Uint16 x1, y1, x2, y2; |
| 24 |
-} Rect2d; |
|
| 25 |
- |
|
| 26 |
-typedef struct {
|
|
| 27 |
- Uint8 reqdraw; |
|
| 28 |
- Uint8 bg[RES], fg[RES]; |
|
| 29 |
- Rect2d bounds; |
|
| 30 | 25 |
} Screen; |
| 31 | 26 |
|
| 32 | 27 |
int WIDTH = 8 * HOR + 8 * PAD * 2; |
| 33 | 28 |
int HEIGHT = 8 * VER + 8 * PAD * 2; |
| 34 | 29 |
int FPS = 30, GUIDES = 0, ZOOM = 2; |
| 35 | 30 |
|
| 36 |
-Uint32 theme[] = {
|
|
| 37 |
- 0x000000, |
|
| 38 |
- 0xFFFFFF, |
|
| 39 |
- 0x72DEC2, |
|
| 40 |
- 0x666666, |
|
| 41 |
- 0x222222}; |
|
| 31 |
+Uint32 *pixels, theme[4]; |
|
| 42 | 32 |
|
| 43 |
-Uint8 icons[][8] = {
|
|
| 33 |
+Uint8 font[][8] = {
|
|
| 44 | 34 |
{0x00, 0x3c, 0x46, 0x4a, 0x52, 0x62, 0x3c, 0x00},
|
| 45 | 35 |
{0x00, 0x18, 0x28, 0x08, 0x08, 0x08, 0x3e, 0x00},
|
| 46 | 36 |
{0x00, 0x3c, 0x42, 0x02, 0x3c, 0x40, 0x7e, 0x00},
|
| ... | ... |
@@ -61,8 +51,6 @@ Uint8 icons[][8] = {
|
| 61 | 51 |
static SDL_Window *gWindow; |
| 62 | 52 |
static SDL_Renderer *gRenderer; |
| 63 | 53 |
static SDL_Texture *gTexture; |
| 64 |
-static Uint32 *pixels; |
|
| 65 |
- |
|
| 66 | 54 |
static Screen screen; |
| 67 | 55 |
static Device *devscreen, *devmouse, *devkey, *devctrl; |
| 68 | 56 |
|
| ... | ... |
@@ -92,18 +80,6 @@ paintpixel(Uint8 *dst, Uint16 x, Uint16 y, Uint8 color) |
| 92 | 80 |
dst[row + 8] |= 1UL << col; |
| 93 | 81 |
} |
| 94 | 82 |
|
| 95 |
-void |
|
| 96 |
-paintchr(Uint8 *dst, Uint16 x, Uint16 y, Uint8 *sprite) |
|
| 97 |
-{
|
|
| 98 |
- Uint16 v, h; |
|
| 99 |
- for(v = 0; v < 8; v++) |
|
| 100 |
- for(h = 0; h < 8; h++) {
|
|
| 101 |
- Uint8 ch1 = ((sprite[v] >> (7 - h)) & 0x1); |
|
| 102 |
- Uint8 ch2 = (((sprite[v + 8] >> (7 - h)) & 0x1) << 1); |
|
| 103 |
- paintpixel(dst, x + h, y + v, ch1 + ch2); |
|
| 104 |
- } |
|
| 105 |
-} |
|
| 106 |
- |
|
| 107 | 83 |
void |
| 108 | 84 |
painticn(Uint8 *dst, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 blend) |
| 109 | 85 |
{
|
| ... | ... |
@@ -131,7 +107,7 @@ clear(Uint32 *dst) |
| 131 | 107 |
void |
| 132 | 108 |
drawpixel(Uint32 *dst, Uint16 x, Uint16 y, Uint8 color) |
| 133 | 109 |
{
|
| 134 |
- if(x >= screen.bounds.x1 && x <= screen.bounds.x2 && y >= screen.bounds.x1 && y <= screen.bounds.y2) |
|
| 110 |
+ if(x >= screen.x1 && x <= screen.x2 && y >= screen.x1 && y <= screen.y2) |
|
| 135 | 111 |
dst[y * WIDTH + x] = theme[color]; |
| 136 | 112 |
} |
| 137 | 113 |
|
| ... | ... |
@@ -188,9 +164,9 @@ drawdebugger(Uint32 *dst, Uxn *u) |
| 188 | 164 |
{
|
| 189 | 165 |
Uint8 i, x, y, b; |
| 190 | 166 |
for(i = 0; i < 0x10; ++i) { /* memory */
|
| 191 |
- x = ((i % 8) * 3 + 3) * 8, y = screen.bounds.x1 + 8 + i / 8 * 8, b = u->wst.dat[i]; |
|
| 192 |
- drawicn(dst, x, y, icons[(b >> 4) & 0xf], 1 + (u->wst.ptr == i), 0); |
|
| 193 |
- drawicn(dst, x + 8, y, icons[b & 0xf], 1 + (u->wst.ptr == i), 0); |
|
| 167 |
+ x = ((i % 8) * 3 + 3) * 8, y = screen.x1 + 8 + i / 8 * 8, b = u->wst.dat[i]; |
|
| 168 |
+ drawicn(dst, x, y, font[(b >> 4) & 0xf], 1 + (u->wst.ptr == i), 0); |
|
| 169 |
+ drawicn(dst, x + 8, y, font[b & 0xf], 1 + (u->wst.ptr == i), 0); |
|
| 194 | 170 |
} |
| 195 | 171 |
for(x = 0; x < 32; ++x) {
|
| 196 | 172 |
drawpixel(dst, x, HEIGHT / 2, 2); |
| ... | ... |
@@ -254,10 +230,10 @@ init(void) |
| 254 | 230 |
clear(pixels); |
| 255 | 231 |
SDL_StartTextInput(); |
| 256 | 232 |
SDL_ShowCursor(SDL_DISABLE); |
| 257 |
- screen.bounds.x1 = PAD * 8; |
|
| 258 |
- screen.bounds.x2 = WIDTH - PAD * 8 - 1; |
|
| 259 |
- screen.bounds.y1 = PAD * 8; |
|
| 260 |
- screen.bounds.y2 = HEIGHT - PAD * 8 - 1; |
|
| 233 |
+ screen.x1 = PAD * 8; |
|
| 234 |
+ screen.x2 = WIDTH - PAD * 8 - 1; |
|
| 235 |
+ screen.y1 = PAD * 8; |
|
| 236 |
+ screen.y2 = HEIGHT - PAD * 8 - 1; |
|
| 261 | 237 |
return 1; |
| 262 | 238 |
} |
| 263 | 239 |
|
| ... | ... |
@@ -377,10 +353,7 @@ sprite_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1) |
| 377 | 353 |
Uint16 a = (m[ptr + 4] << 8) + m[ptr + 5]; |
| 378 | 354 |
Uint8 source = (b1 >> 4) & 0xf; |
| 379 | 355 |
Uint8 *layer = source % 2 ? screen.fg : screen.bg; |
| 380 |
- if(source / 2) |
|
| 381 |
- paintchr(layer, x, y, &m[a]); |
|
| 382 |
- else |
|
| 383 |
- painticn(layer, x, y, &m[a], b1 & 0xf); |
|
| 356 |
+ painticn(layer, x, y, &m[a], b1 & 0xf); |
|
| 384 | 357 |
screen.reqdraw = 1; |
| 385 | 358 |
} |
| 386 | 359 |
return b1; |