利用 Ophis 编写 Commodore 64 programs PRG 程序(一)

参考Producing Commodore 64 programsWriting the actual code
本节将实现简单的hello world程序,从而形成对ophis的初步认识

准备工作

  1. 请配置好Ophis,MacOS配置方法可参考Mac OS 安装 Ophis
  2. 了解PRG 程序文件结构
  3. 了解汇编语言

编写代码

以输出HELLO, WORLD!为例,详见注释

; test.oph

.word $0801
.org  $0801						; BASIC内存开始地址

; BASIC部分
        .word next, 10			; 下一行与当前行号
        .byte $9e,"2061",0		; 调用机器代码语句: SYS 2061
next:   .word 0					; 结束程序

; 汇编部分
        ldx #0					; [a2 00]		x = 0
loop:   lda hello, x			; [bd 1b 08]	a = hello[x]
        beq done				; [f0 06]		if(a == 0) goto done;
        jsr $ffd2				; [20 d2 ff]	调用KERNAL的打印字符子程序
        inx						; [e8]			x++
        bne loop				; [d0 f5]		if(a != 0) goto loop;
done:   rts						; [60 48]		返回BASIC

hello:  .byte "HELLO, WORLD!", 0	; 首地址<0x081b>

.outfile "test.prg"				; 输出文件名

汇编

输入命令

ophis -v test.oph

将在同目录生成文件test.prg,利用C语言打印文件二进制与十六进制编码如下

00000001 00001000 00001011 00001000 00001010 00000000 10011110 00110010 01 08 0b 08 0a 00 9e 32 
00110000 00110110 00110001 00000000 00000000 00000000 10100010 00000000 30 36 31 00 00 00 a2 00 
10111101 00011011 00001000 11110000 00000110 00100000 11010010 11111111 bd 1b 08 f0 06 20 d2 ff 
11101000 11010000 11110101 01100000 01001000 01000101 01001100 01001100 e8 d0 f5 60 48 45 4c 4c 
01001111 00101100 00100000 01010111 01001111 01010010 01001100 01000100 4f 2c 20 57 4f 52 4c 44 
00100001 00000000														21 00 

效果演示

c64

前往下一节

猜你喜欢

转载自blog.csdn.net/u011570312/article/details/114943848
今日推荐