it works
This commit is contained in:
parent
772c294fee
commit
ecedd8fd59
2 changed files with 92 additions and 59 deletions
|
@ -49,4 +49,6 @@ https://github.com/empathicqubit/vscode-cc65-debugger/tree/master/src/__tests__/
|
||||||
|
|
||||||
https://archive.org/details/The_Graphics_Book_for_the_Commodore_64/page/n25/mode/2up
|
https://archive.org/details/The_Graphics_Book_for_the_Commodore_64/page/n25/mode/2up
|
||||||
|
|
||||||
http://www.appleoldies.ca/cc65/docs/shr/shrworld.pd
|
http://www.appleoldies.ca/cc65/docs/shr/shrworld.pd
|
||||||
|
|
||||||
|
https://archive.org/details/The_Graphics_Book_for_the_Commodore_64/page/n59
|
147
src/main.c
147
src/main.c
|
@ -13,18 +13,17 @@
|
||||||
|
|
||||||
|
|
||||||
unsigned short i;
|
unsigned short i;
|
||||||
unsigned short x; // maybe if the ant does not go tooo far it could be an int..
|
short x; // maybe if the ant does not go tooo far it could be an int..
|
||||||
BYTE y;
|
short y;
|
||||||
BYTE direction; // 0 = right, 64 = up, 128 = left, 192 = down
|
short direction; // 0 = right, 64 = up, 128 = left, 192 = down
|
||||||
void setAndClearHiRes(void) {
|
void setHiRes(void) {
|
||||||
// Hi-res is turned on by setting bits 5 and 6 (bit 6 must be set in any event)
|
|
||||||
// of register 17 of the VIC and clearing bit 4 of register 22.
|
|
||||||
|
|
||||||
|
|
||||||
*(BYTE*)0xd011 = *(BYTE*)0xd011 | 0xb0 ; // Graphics on
|
*(BYTE*)0xd011 = *(BYTE*)0xd011 | 0xb0 ; // Graphics on
|
||||||
*(BYTE*)0xd016 = *(BYTE*)0xd016 & 240; //Multi color off
|
*(BYTE*)0xd016 = *(BYTE*)0xd016 & 240; //Multi color off
|
||||||
*(BYTE*)0xd018 = *(BYTE*)0xd018 | 8 ; // Graphics to $2000
|
*(BYTE*)0xd018 = *(BYTE*)0xd018 | 8 ; // Graphics to $2000
|
||||||
|
}
|
||||||
|
void clearHiRes(void) {
|
||||||
|
// Hi-res is turned on by setting bits 5 and 6 (bit 6 must be set in any event)
|
||||||
|
// of register 17 of the VIC and clearing bit 4 of register 22.
|
||||||
// Clear memory
|
// Clear memory
|
||||||
for (i =0;i< 8000; i++)
|
for (i =0;i< 8000; i++)
|
||||||
{
|
{
|
||||||
|
@ -34,85 +33,117 @@ void setAndClearHiRes(void) {
|
||||||
// Clear colors
|
// Clear colors
|
||||||
for (i =0;i< 1000; i++)
|
for (i =0;i< 1000; i++)
|
||||||
{
|
{
|
||||||
*(BYTE*)(0x400+i) = 0xF0;
|
*(BYTE*)(0x400+i) = 0xf0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int power2(int exponent)
|
void fillHiRes(void) {
|
||||||
{
|
// Hi-res is turned on by setting bits 5 and 6 (bit 6 must be set in any event)
|
||||||
int result=1;
|
// of register 17 of the VIC and clearing bit 4 of register 22.
|
||||||
for (exponent; exponent>0; exponent--)
|
// Clear memory
|
||||||
|
for (i =0;i< 8000; i++)
|
||||||
{
|
{
|
||||||
result = result * 2;
|
*(BYTE*)(0x2000+i) = 0xff;
|
||||||
}
|
}
|
||||||
return result;
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void setAndClearHiRes(){
|
||||||
|
setHiRes();
|
||||||
|
clearHiRes();
|
||||||
}
|
}
|
||||||
|
|
||||||
// need to think
|
// need to think
|
||||||
BYTE isPositionBlack(unsigned short x, BYTE y)
|
BYTE isPositionWhite(short x, short y)
|
||||||
{
|
{
|
||||||
unsigned short ra = (320 * (BYTE)(y/8)) + (y & 7);
|
short ra = (320 * (short)(y/8)) + (y & 7);
|
||||||
unsigned short ba = 8 * (BYTE)(x/8);
|
short ba = 8 * (short)(x/8);
|
||||||
unsigned short ma = 255 - power2((7-(x & 7)));
|
short ma = 1 << ((7-(x & 7)));
|
||||||
unsigned short sa = 0x2000;
|
short sa = 0x2000;
|
||||||
unsigned short ad = sa+ra+ba;
|
short ad = sa+ra+ba;
|
||||||
return 1;
|
return *(short*)(ad) & ma;
|
||||||
// return *(BYTE*)(ad) & ma;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// https://archive.org/details/The_Graphics_Book_for_the_Commodore_64/page/n129/
|
// https://archive.org/details/The_Graphics_Book_for_the_Commodore_64/page/n129/
|
||||||
void setPositionWhite(unsigned short x, BYTE y)
|
void setPositionWhite(short x, short y)
|
||||||
{
|
{
|
||||||
unsigned short ra = (320 * (BYTE)(y/8)) + (y & 7);
|
short ra = (320 * (short)(y/8)) + (y & 7);
|
||||||
unsigned short ba = 8 * (BYTE)(x/8);
|
short ba = 8 * (short)(x/8);
|
||||||
unsigned short ma = power2((7-(x & 7)));
|
short ma = 1 << ((7-(x & 7)));
|
||||||
unsigned short sa = 0x2000;
|
short sa = 0x2000;
|
||||||
unsigned short ad = sa+ra+ba;
|
short ad = sa+ra+ba;
|
||||||
*(unsigned short*)(ad) = *(unsigned short*)(ad) | ma;
|
*(short*)(ad) = *(short*)(ad) | ma;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPositionBlack(unsigned short x, BYTE y)
|
void setPositionBlack(unsigned short x, unsigned short y)
|
||||||
{
|
{
|
||||||
unsigned short ra = (320 * (BYTE)(y/8)) + (y & 7);
|
short ra = (320 * (short)(y/8)) + (y & 7);
|
||||||
unsigned short ba = 8 * (BYTE)(x/8);
|
short ba = 8 * (short)(x/8);
|
||||||
unsigned short ma = 255 - power2((7-(x & 7)));
|
short ma = (1 << ((7-(x & 7))));
|
||||||
unsigned short sa = 0x2000;
|
short sa = 0x2000;
|
||||||
unsigned short ad = sa+ra+ba;
|
short ad = sa+ra+ba;
|
||||||
*(unsigned short*)(ad) = *(unsigned short*)(ad) & ma;
|
*(short*)(ad) = (*(short*)(ad)) & ~ma;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void makeMove() {
|
void moveForward() {
|
||||||
if (isPositionBlack(x,y)) {
|
if (direction == 0) {
|
||||||
setPositionWhite(x,y);
|
x = x+1;
|
||||||
direction = direction - 64;
|
} else if (direction == 64) {
|
||||||
} else {
|
y = y+1;
|
||||||
setPositionBlack(x,y);
|
} else if (direction == 128) {
|
||||||
direction = direction + 64;
|
x = x-1;
|
||||||
|
} else if (direction == 192) {
|
||||||
|
y = y-1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void turnLeft(){
|
||||||
|
direction = direction + 64;
|
||||||
|
if (direction >= 255)
|
||||||
|
direction = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void turnRight(){
|
||||||
|
direction = direction - 64;
|
||||||
|
if (direction <0)
|
||||||
|
direction = 192;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void makeMove() {
|
||||||
|
if (isPositionWhite(x,y)) {
|
||||||
|
turnRight();
|
||||||
|
setPositionBlack(x,y);
|
||||||
|
} else {
|
||||||
|
turnLeft();
|
||||||
|
setPositionWhite(x,y);
|
||||||
|
}
|
||||||
|
moveForward();
|
||||||
|
}
|
||||||
|
|
||||||
unsigned short line;
|
unsigned short line;
|
||||||
|
unsigned short foo;
|
||||||
|
unsigned short j;
|
||||||
int main(void) {
|
int main(void) {
|
||||||
|
|
||||||
|
setAndClearHiRes();
|
||||||
|
for (i = 0;i<50;i++){
|
||||||
|
for (j= 0;j<50;j++){
|
||||||
|
setPositionWhite(i,j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (i = 0;i<50;i++){
|
||||||
|
for (j= 0;j<50;j++){
|
||||||
|
setPositionBlack(i,j);
|
||||||
|
}
|
||||||
|
}
|
||||||
x = 160;
|
x = 160;
|
||||||
y = 100;
|
y = 100;
|
||||||
direction = 0;
|
direction = 0;
|
||||||
setAndClearHiRes();
|
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
if (direction == 0) {
|
makeMove();
|
||||||
x = x+1;
|
|
||||||
} else if (direction == 64) {
|
|
||||||
y = y +1;
|
|
||||||
} else if (direction == 128) {
|
|
||||||
x = x-1;
|
|
||||||
} else {
|
|
||||||
y = y -1;
|
|
||||||
}
|
|
||||||
makeMove();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Add table
Reference in a new issue