Bug corrections concerning the cursor in editor
This commit is contained in:
parent
75eb6acada
commit
46d5fd45bf
61
gfx.asm
61
gfx.asm
|
@ -8,6 +8,7 @@
|
|||
.export _gfx_init
|
||||
.export _gfx_fill
|
||||
.export _gfx_pixel
|
||||
.export _gfx_get_pixel
|
||||
.export _gfx_refresh
|
||||
|
||||
|
||||
|
@ -101,7 +102,6 @@ init_end:
|
|||
;**************************
|
||||
;void __fastcall__ gfx_fill( uint8_t color )
|
||||
; Fills the screen with the given color
|
||||
; TMP1 and PTR1 and PTR2 are overwritten
|
||||
_gfx_fill:
|
||||
; TODO SWITCH PAGES !!
|
||||
;saving the context
|
||||
|
@ -258,6 +258,65 @@ oddeven:
|
|||
RTS
|
||||
|
||||
|
||||
;**************************
|
||||
;uint8_t __fastcall__ gfx_get_pixel( uint8_t coord_x, uint8_t coord_y )
|
||||
; Returns the pixel's color
|
||||
_gfx_get_pixel:
|
||||
TAX ; coord_y
|
||||
|
||||
;saving the context
|
||||
LDA ptr1
|
||||
JSR pusha
|
||||
LDA ptr2
|
||||
JSR pusha
|
||||
|
||||
; Page's address to ptr1
|
||||
LDA #<Page1
|
||||
STA ptr1
|
||||
LDA #>Page1
|
||||
STA ptr1+1
|
||||
; Line's adress to ptr2
|
||||
TXA
|
||||
LSR
|
||||
ASL
|
||||
TAY
|
||||
LDA (ptr1),Y
|
||||
STA ptr2
|
||||
INY
|
||||
LDA (ptr1),Y
|
||||
STA ptr2+1
|
||||
; get coord_x
|
||||
LDY #2 ;there were 4 pushes to save registers
|
||||
LDA (sp),Y
|
||||
TAY
|
||||
TXA
|
||||
AND #1 ; test line parity to read the correct nybble
|
||||
BEQ even_2
|
||||
odd_2: LDA (ptr2),Y
|
||||
LSR ; color is in lo nybble
|
||||
LSR
|
||||
LSR
|
||||
LSR
|
||||
CLC
|
||||
BCC end_2
|
||||
even_2: LDA (ptr2),Y
|
||||
AND #$0F ; color is in hi nybble
|
||||
end_2: TAX
|
||||
|
||||
;restoring the context
|
||||
JSR popa
|
||||
STA ptr2
|
||||
JSR popa
|
||||
STA ptr1
|
||||
JSR popa ;1st parameter
|
||||
|
||||
; return value
|
||||
TXA
|
||||
LDX #0
|
||||
|
||||
RTS
|
||||
|
||||
|
||||
;**************************
|
||||
;void __fastcall__ gfx_refresh( void )
|
||||
; Updates the screen by displaying the Future Page which becomes Current
|
||||
|
|
9
gfx.h
9
gfx.h
|
@ -1,11 +1,18 @@
|
|||
#ifndef __GFX_H__
|
||||
#define __GFX_H__
|
||||
|
||||
|
||||
// Restores text mode
|
||||
void __fastcall__ mode_text( void );
|
||||
// Switches to the desired res and mode.
|
||||
// Always displays page 1
|
||||
void __fastcall__ gfx_init( uint8_t resolution, uint8_t mode );
|
||||
// Fills the screen with the given color
|
||||
void __fastcall__ gfx_fill( uint8_t color );
|
||||
// Draws a pixel at the given coordinates
|
||||
void __fastcall__ gfx_pixel( uint8_t color, uint8_t coord_x, uint8_t coord_y );
|
||||
// Returns the pixel's color
|
||||
uint8_t __fastcall__ gfx_get_pixel( uint8_t coord_x, uint8_t coord_y );
|
||||
// Updates the screen by displaying the Future Page which becomes Current
|
||||
void __fastcall__ gfx_refresh( void );
|
||||
|
||||
enum eMode {
|
||||
|
|
29
gol_apple2.c
29
gol_apple2.c
|
@ -147,12 +147,6 @@ void draw_cells( void ) {
|
|||
}
|
||||
}
|
||||
|
||||
void clear_cursor( const uint8_t x, const uint8_t y )
|
||||
{
|
||||
if( Cells[x][y] == DEAD ) {
|
||||
gfx_pixel( BLACK, x, y );
|
||||
}
|
||||
}
|
||||
|
||||
void editor( void )
|
||||
{
|
||||
|
@ -162,9 +156,11 @@ void editor( void )
|
|||
#define KEY_RIGHT 'l'
|
||||
|
||||
uint8_t quit, x, y;
|
||||
uint8_t color_pixel;
|
||||
|
||||
x = NB_COLUMNS >> 1u;
|
||||
y = NB_LINES >> 1u;
|
||||
y = (NB_LINES >> 1u) + 1;
|
||||
color_pixel = gfx_get_pixel( x, y );
|
||||
|
||||
quit = 0;
|
||||
while ( quit == 0)
|
||||
|
@ -172,19 +168,19 @@ void editor( void )
|
|||
KeyPressed = cgetc();
|
||||
switch (KeyPressed) {
|
||||
case KEY_LEFT:
|
||||
clear_cursor(x,y);
|
||||
gfx_pixel( color_pixel, x, y );
|
||||
if( x > 1u ) { --x; }
|
||||
break;
|
||||
case KEY_DOWN:
|
||||
clear_cursor(x,y);
|
||||
gfx_pixel( color_pixel, x, y );
|
||||
if( y < NB_LINES-2u ) { ++y; }
|
||||
break;
|
||||
case KEY_UP:
|
||||
clear_cursor(x,y);
|
||||
gfx_pixel( color_pixel, x, y );
|
||||
if( y > 1u ) { --y; }
|
||||
break;
|
||||
case KEY_RIGHT:
|
||||
clear_cursor(x,y);
|
||||
gfx_pixel( color_pixel, x, y );
|
||||
if( x < NB_COLUMNS-2u ) { ++x; }
|
||||
break;
|
||||
case ' ':
|
||||
|
@ -198,6 +194,7 @@ void editor( void )
|
|||
quit = 1;
|
||||
break;
|
||||
}
|
||||
color_pixel = gfx_get_pixel( x, y );
|
||||
gfx_pixel( WHITE, x, y ); //cursor
|
||||
}
|
||||
|
||||
|
@ -228,16 +225,16 @@ void run( void )
|
|||
uint16_t nb_iterations = 2u;
|
||||
KeyPressed = NO_KEY;
|
||||
|
||||
cursor(0);
|
||||
gotoxy( 0u, NB_LINES );
|
||||
printf("Iteration:1 (R)eset (E)ditor (Q)uit");
|
||||
//cursor(0);
|
||||
//gotoxy( 0u, NB_LINES );
|
||||
//printf("Iteration:1 (R)eset (E)ditor (Q)uit");
|
||||
while( KeyPressed == NO_KEY)
|
||||
{
|
||||
/* Evolving the cells */
|
||||
update( );
|
||||
/* Printing iterations */
|
||||
gotoxy(10u, NB_LINES);
|
||||
printf( itoa(nb_iterations++, str_nb_iteration, 10) );
|
||||
//gotoxy(10u, NB_LINES);
|
||||
//printf( itoa(nb_iterations++, str_nb_iteration, 10) );
|
||||
/* Testing key pressed */
|
||||
if( kbhit() ) {
|
||||
KeyPressed = cgetc();
|
||||
|
|
Loading…
Reference in New Issue