From: Robin Krens <robin@robinkrens.nl>
Date: Sat, 11 Jun 2022 22:59:35 +0000 (+0200)
Subject: main: attribute naked not working, use .s instead
X-Git-Url: https://robinkrens.nl/gitweb/?a=commitdiff_plain;h=7156a11b2a36da2dc2ab91da86551f5ebf60564f;p=swan-dev

main: attribute naked not working, use .s instead
---

diff --git a/Makefile b/Makefile
index 5ee33f7..bc3b433 100644
--- a/Makefile
+++ b/Makefile
@@ -22,13 +22,13 @@ LDFILE = swan.ld
 
 
 $(ODIR)/%.o: $(SDIR)/%.c
-	$(CC) -c $(INC) -o $@ $< $(CFLAGS)
+	$(CC) -c $(INC) -o $@ $< $(CFLAGS) 
 
 $(ODIR)/entry.o: $(SDIR)/entry.S
 	$(CC) -c $(INC) -o $@ $< $(CFLAGS)
 
 $(OUT): $(OBJS)
-	$(LD) -T $(LDFILE) $^ -o $(OUT)
+	$(LD) -T $(LDFILE) $^ -o $(OUT) -Map=output.map
 
 add:
 	./romheader
diff --git a/src/entry.S b/src/entry.S
index e5fae8b..3ae396c 100644
--- a/src/entry.S
+++ b/src/entry.S
@@ -12,7 +12,10 @@
 .extern _etext
 .extern _sdata
 .extern _edata
+.extern scroll_video
+
 .global _start
+.global dummyS_isr
 
 _start:
 	# reset flags and registers
@@ -22,6 +25,12 @@ _start:
 	mov %ax,%bx
 	mov %ax,%bp
 	mov %ax,%ss
+	
+	# set correct segment (use at
+	# position 0x2000 + 0 + IP
+	mov $0x2000, %bx
+	mov %bx, %cs
+	xor %bx, %bx
 
 	# set stack pointer for wonderswan
 	# color
@@ -46,9 +55,20 @@ copy_to_ram:
 	xor %ax, %ax
 	mov %ax, %ds
 
+
 	# jump to C
 	call main
 
+dummyS_isr:
+	push %ax
+	call scroll_video
+	;xor %ax, %ax
+	;in $0x12, %al
+	;inc %al
+	;out %al, $0x12
+	pop %ax
+	iret
+
 	# should not be here
 loop:	nop
 	jmp loop
diff --git a/src/main.c b/src/main.c
index 43289fc..7690c66 100644
--- a/src/main.c
+++ b/src/main.c
@@ -10,6 +10,8 @@
 #include <config.h>
 #include <interrupt.h>
 
+extern void * dummyS_isr;
+
 /* sprite data */
 unsigned char bgtile_gfx[] = {
   0x31, 0x22, 0x31, 0x32, 0x22, 0x31, 0x23, 0x21, 0x13, 0x13, 0x31, 0x32,
@@ -59,25 +61,69 @@ unsigned char inport(unsigned char portnr)
 	return val;
 }
 
-__attribute__ ((naked)) void * dummy_isr(void)
+static void __attribute__((used)) dummy() 
 {
-	int a = 2;
-	a *= 2;
-	while(1);
+	__asm__("iret");
 }
 
+//__attribute__((naked)) void dummy_isr(void)
+//{
+//	__asm__("push %ax\n\t"
+//		"push %bx\n\t"
+//		"popw %bp\n\t" /* HACK: directly pop bp again */
+//	       );
+//
+//	//unsigned char val = inport(IO_BG_X);
+//	//val++;
+//
+//	//outport(IO_BG_X, val);
+//	//outport(IO_INT_ACK, INT_VBLANK_START);
+//	__asm__("pop %ax\n\t"
+//		"pop %bx\n\t"
+//	       );
+//
+//	__asm__("iret");
+//}
+
 void setup_ivec(void)
 {
 	outport(IO_INT_BASE, INT_BASE);
 
 	unsigned short * test_vec = (INT_BASE + INTVEC_VBLANK_START) << 2;
-	*test_vec++ = (&dummy_isr);
+	*test_vec++ = (&dummyS_isr);
 	*test_vec = (0x2000);
 
+	unsigned short * keyboard_intr = (INT_BASE + INTVEC_KEY_PRESS) << 2;
+	*keyboard_intr++ = (&dummyS_isr);
+	*keyboard_intr = (0x2000);
+
 	outport(IO_INT_ENABLE, INT_VBLANK_START);
+	//outport(IO_INT_ENABLE, INT_KEY_PRESS);
 	__asm__("sti");
 }
 
+static unsigned cnt = 0;
+
+void scroll_video(void)
+{
+	unsigned char val = inport(IO_FG_X);
+
+	cnt++;
+	if (cnt > 10) {
+		cnt = 0;
+		val++;
+	}
+	
+	outport(IO_FG_X, val);
+	outport(IO_INT_ACK, INT_VBLANK_START);
+	
+	outport(IO_FG_WIN_X0, cnt);
+	outport(IO_FG_WIN_Y0, cnt);
+	outport(IO_FG_WIN_X1, SCREEN_WIDTH - cnt);
+	outport(IO_FG_WIN_Y1, SCREEN_HEIGHT - cnt);
+
+}
+
 void init_video(void)
 {
 }
@@ -125,6 +171,9 @@ int main(void)
 	
 	outport(IO_DISPLAY_CTRL, FG_OUT_WIN | FG_ON);
 
+	int a = 0;
+	a++;
+
 	while(1) {
 	}