Linien und Pixel mit dem cc65 und ASM für den Plus4. Da es beim cc65 keine Grafikroutinen gibt für den Plus4, musste ich mir notgedrungen welche anlegen.Eine "0" am Ende der Werteeingabe für Linie-Pixel ist "löschen" und eine "1" zeichnen.
Der Grafikbereich geht beim Plus4 von $2000-$3fff. Mit den Pokebefehlen eingestellt.
Die Eingabe der Werte habe ich erstmal an freie Speicherplätze gelegt, wo ich meine, das sie vom Programm nicht zerstört werden. Vielleicht kennt jemand noch andere möglichkeiten für den cc65 und Plus4.
Dazu habe ich auch auch mal eine Sin-Cos-Tabelle erstellt.
Compiliert habe ich mit : cl65 -t plus4 -O -o test.prg test.c plot-linie.s --config plus4.cfg
linie-absolut,linieto-absolut,linieto-relativ,pixel-absolut,pixel-relative zum aufrufen.
Die Funktionen sollte man der Übersicht wegen auslagern und dann im Kopf des Programmes aufrufen.
test.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <ctype.h>
#include <stdint.h>
#include <peekpoke.h>
void __fastcall__ set_pixel(void);
void __fastcall__ clear_pixel(void);
void __fastcall__ set_linie(void);
void __fastcall__ clear_linie(void);
unsigned int *xx1=4072;
unsigned char *yy1=4074;
unsigned int *xx2=4075;
unsigned char *yy2=4077;
unsigned int haltex;
unsigned char haltey;
static const int sinus[181] = {
0 ,18 ,36 ,54 ,71 ,89 ,107 ,125 ,143 ,160 ,
178 ,195 ,213 ,230 ,248 ,265 ,282 ,299 ,316 ,333 ,
350 ,367 ,384 ,400 ,416 ,433 ,449 ,465 ,481 ,496 ,
512 ,527 ,543 ,558 ,573 ,587 ,602 ,616 ,630 ,644 ,
658 ,672 ,685 ,698 ,711 ,724 ,737 ,749 ,761 ,773 ,
784 ,796 ,807 ,818 ,828 ,839 ,849 ,859 ,868 ,878 ,
887 ,896 ,904 ,912 ,920 ,928 ,935 ,943 ,949 ,956 ,
962 ,968 ,974 ,979 ,984 ,989 ,994 ,998 ,1002 ,1005 ,
1008 ,1011 ,1014 ,1016 ,1018 ,1020 ,1022 ,1023 ,1023 ,1024 ,
1024 ,1024 ,1023 ,1023 ,1022 ,1020 ,1018 ,1016 ,1014 ,1011 ,
1008 ,1005 ,1002 ,998 ,994 ,989 ,984 ,979 ,974 ,968 ,
962 ,956 ,949 ,943 ,935 ,928 ,920 ,912 ,904 ,896 ,
887 ,878 ,868 ,859 ,849 ,839 ,828 ,818 ,807 ,796 ,
784 ,773 ,761 ,749 ,737 ,724 ,711 ,698 ,685 ,672 ,
658 ,644 ,630 ,616 ,602 ,587 ,573 ,558 ,543 ,527 ,
512 ,496 ,481 ,465 ,449 ,433 ,416 ,400 ,384 ,367 ,
350 ,333 ,316 ,299 ,282 ,265 ,248 ,230 ,213 ,195 ,
178 ,160 ,143 ,125 ,107 ,89 ,71 ,54 ,36 ,18 ,
0 ,
};
static const int cosinus[181] = {
1024 ,1024 ,1023 ,1023 ,1022 ,1020 ,1018 ,1016 ,1014 ,1011 ,
1008 ,1005 ,1002 ,998 ,994 ,989 ,984 ,979 ,974 ,968 ,
962 ,956 ,949 ,943 ,935 ,928 ,920 ,912 ,904 ,896 ,
887 ,878 ,868 ,859 ,849 ,839 ,828 ,818 ,807 ,796 ,
784 ,773 ,761 ,749 ,737 ,724 ,711 ,698 ,685 ,672 ,
658 ,644 ,630 ,616 ,602 ,587 ,573 ,558 ,543 ,527 ,
512 ,496 ,481 ,465 ,449 ,433 ,416 ,400 ,384 ,367 ,
350 ,333 ,316 ,299 ,282 ,265 ,248 ,230 ,213 ,195 ,
178 ,160 ,143 ,125 ,107 ,89 ,71 ,54 ,36 ,18 ,
0 ,-18 ,-36 ,-54 ,-71 ,-89 ,-107 ,-125 ,-143 ,-160 ,
-178 ,-195 ,-213 ,-230 ,-248 ,-265 ,-282 ,-299 ,-316 ,-333 ,
-350 ,-367 ,-384 ,-400 ,-416 ,-433 ,-449 ,-465 ,-481 ,-496 ,
-512 ,-527 ,-543 ,-558 ,-573 ,-587 ,-602 ,-616 ,-630 ,-644 ,
-658 ,-672 ,-685 ,-698 ,-711 ,-724 ,-737 ,-749 ,-761 ,-773 ,
-784 ,-796 ,-807 ,-818 ,-828 ,-839 ,-849 ,-859 ,-868 ,-878 ,
-887 ,-896 ,-904 ,-912 ,-920 ,-928 ,-935 ,-943 ,-949 ,-956 ,
-962 ,-968 ,-974 ,-979 ,-984 ,-989 ,-994 ,-998 ,-1002 ,-1005 ,
-1008 ,-1011 ,-1014 ,-1016 ,-1018 ,-1020 ,-1022 ,-1023 ,-1023 ,-1024 ,
-1024 ,
};
int pixel_ab(unsigned int x1, unsigned char y1,unsigned char l) {
*xx1=x1;
*yy1=y1;
haltex=x1;
haltey=y1;
if (l == 0){
clear_pixel();
return 0;
}
set_pixel();
}
int pixel_re(unsigned int x1, unsigned char y1,unsigned char l) {
*xx1=haltex+x1;
*yy1=haltey+y1;
haltex=x1;
haltey=y1;
if (l == 0){
clear_pixel();
return 0;
}
set_pixel();
}
int linie_ab(unsigned int x1, unsigned char y1, unsigned x2, unsigned char y2, unsigned char l) {
*xx1=x1;
*yy1=y1;
*xx2=x2;
*yy2=y2;
haltex=x2;
haltey=y2;
if (l == 0){
clear_linie();
return 0;
}
set_linie();
}
int linieto_re(unsigned int x2, unsigned char y2, unsigned char l) {
*xx1=haltex;
*yy1=haltey;
*xx2=haltex+x2;
*yy2=haltey+y2;
haltex=*xx2;
haltey=*yy2;
if (l == 0){
clear_linie();
return 0;
}
set_linie();
}
int linieto_ab(unsigned int x2, unsigned char y2, unsigned char l) {
*xx1=haltex;
*yy1=haltey;
*xx2=x2;
*yy2=y2;
haltex=x2;
haltey=y2;
if (l == 0){
clear_linie();
return 0;
}
set_linie();
}
int main(void) {
static uint16_t x;
static uint16_t xx2,yy2;
POKE(0xff06,(PEEK(0xff06) & 223 | 32));
POKE(0xff12,(PEEK(0xff12) & 247 | 8));
for (x=0x800; x<0xc00; ++x) {
POKE(x,6);
}
for (x=0xc00; x<0x1000; ++x) {
POKE(x,54);
}
for (x=0x2000; x<0x3fff; ++x) {
POKE(x,0);
}
for (x=0; x<180; x=x+4) {
xx2=((60*(long)sinus[x])>> 10);
yy2=((60*(long)cosinus[x])>> 10);
linie_ab(160,100,160+xx2,100+yy2,1);
}
for (x=180; x>0; x=x-4) {
xx2=((60*(long)sinus[x])>> 10);
yy2=((60*(long)cosinus[x])>> 10);
linie_ab(160,100,160-xx2,100-yy2,1);
}
cgetc();
}
Alles anzeigen
Pixel-Linie-ASM für cc65 :
plot-linie.s
.export _set_pixel
.export _clear_pixel
.export _set_linie
.export _clear_linie
xxk = 4072
yyk = 4074
xxk1 = 4075
yyk1 = 4077
aa = 216
bb = 217
offx = 218
msk = 219
use = 220
xk = 222
dif0 = 223
dif1 = 224
dif2 = 225
dif3 = 226
dif4 = 227
dif5 =228
zwn = 229
za = 230
flg = 231
_clear_pixel:
ldx #$00
jmp pl1
_set_pixel:
ldx #$80
pl1:
stx flg
jsr testcor
jsr hposn
jmp plt
_clear_linie:
ldx #$00
jmp pl111
_set_linie:
ldx #$80
pl111:
jsr pl1
jsr testcor1
jmp hline
testcor:
ldy yyk
lda xxk
ldx xxk+1
rts
testcor1:
ldy yyk1
lda xxk1
ldx xxk1+1
rts
hposn:
sty yk
sta xkl
stx xkh
sta xk
stx xk+1
tya
lsr
lsr
lsr
tax
lda mulh,x
sta bb
txa
and #3
tax
lda mull,x
sta aa
tya
and #7
clc
adc aa
sta aa
lda xk
and #$f8
sta offx
lda #$20
ora bb
sta bb
clc
lda aa
adc offx
sta aa
lda bb
adc xk+1
sta bb
lda xk
and #7
eor #7
tax
lda msktab,x
sta msk
rts
plt:
ldy #0
php
lda msk
bit flg
bmi pl2
eor #$ff
and (aa),y
.byte $2c
pl2:
ora (aa),y
sta (aa),y
lda aa
sta use
lda bb
lsr
ror use
lsr
ror use
lsr
ror use
sta use+1
sta (use),y
ldy zwn
plp
rts
unten:
lda aa
and #7
cmp #7
beq un1
sec
lda #0
bcs un2
un1:
lda #$38
inc bb
un2:
adc aa
sta aa
lda #0
adc bb
sta bb
rts
uo:
bmi unten
oben:
lda aa
and #7
beq ob1
clc
lda #$ff
bcc ob2
ob1:
lda #$c7
dec bb
ob2:
adc aa
sta aa
lda bb
sbc #0
sta bb
rts
rechts:
lsr msk
bcc re2
ror msk
lda aa
iny
clc
adc #8
sta aa
bcc re2
inc bb
re2:
rts
rl:
bpl rechts
links:
asl msk
bcc l11
rol msk
lda aa
dey
sec
l13:
sbc #8
sta aa
bcs l11
dec bb
l11:
rts
hline:
pha
lda xkh
lsr
lda xkl
ror
lsr
lsr
sta zwn
pla
pha
sec
sbc xkl
pha
txa
sbc xkh
sta dif3
bcs l3
pla
eor #$ff
adc #1
pha
lda #0
sbc dif3
l3:
sta dif1
sta dif5
pla
sta dif0
sta dif4
pla
sta xkl
stx xkh
tya
clc
sbc yk
bcc l4
eor #$ff
adc #$fe
l4:
sta dif2
sty yk
ror dif3
sec
sbc dif0
tax
lda #$ff
sbc dif1
sta za
ldy zwn
bcs l5
l1:
asl
jsr rl
sec
l5:
lda dif4
adc dif2
sta dif4
lda dif5
sbc #0
l2:
sta dif5
sty zwn
jsr plt
inx
bne l6
inc za
bne l6
rts
l6:
lda dif3
bcs l1
jsr uo
clc
lda dif4
adc dif0
sta dif4
lda dif5
adc dif1
bvc l2
xkl: .byte 1
xkh: .byte 1
yk: .byte 1
mulh: .byte 0,1,2,3,5,6,7,8,10,11,12,13,15,16,17,18,20,21,22,23,25,26,27,28,30,31
mull: .byte $00, $40, $80, $c0
msktab: .byte 1,2,4,8,16,32,64,128
Alles anzeigen