Jump to content

6502 Machine Language

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
7 replies to this topic

#1
Guest_Jonas_*

Guest_Jonas_*
  • Guests
I was waxing a bit nostaligc to my early computer days. My first real programming came in basic, but then from there I was engrossed in the apple II 6502 machine language. Writing code in hexadecimal was amazingly fun. :)

Just curious if anyone else here had any experience with the old apple 6502 machine language.

#2
Guest_Jordan_*

Guest_Jordan_*
  • Guests
I've never heard of this language. Got any code you can paste in?

#3
Nightracer

Nightracer

    Programmer

  • Members
  • PipPipPipPip
  • 131 posts
I have no experience with this and Im sure the code looks very alien!
It would really be very complex and probably take 100x the time it takes to complete programming tasks with modern languages.

#4
DevilsCharm

DevilsCharm

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 884 posts
What's the deal with this "hexadecimal" thing? I have no idea what that means, and it sounds incredibly complex.

#5
Guest_Jonas_*

Guest_Jonas_*
  • Guests
You guys are so lucky. I used to own this book back in the day. Now it is online for free. I think the last publication was 1983.

http://www.atariarchives.org/mlb/

Here is part of the code from a game called microchess:

;***********************************************************************

;

;  MicroChess (c) 1996-2002 Peter Jennings, peterj@benlo.com 

;

;***********************************************************************

; I have been given permission to distribute this program by the

; author and copyright holder, Peter Jennings.  Please get his 

; permission if you wish to re-distribute a modified copy of 

; this file to others.  He specifically requested that his 

; copyright notice be included in the source and binary images.

; Thanks! 

;

; modified by Daryl Rictor to work over a serial terminal connection, August 2002.

;

; 6551 I/O Port Addresses

;

ACIADat	= 	$7F70

ACIASta	=	$7F71

ACIACmd	=	$7F72

ACIACtl	=	$7F73

;

; page zero variables

;

BOARD   =	$50 

BK      =	$60 

PIECE   =	$B0 

SQUARE  =	$B1 

SP2     =	$B2 

SP1     =	$B3 

INCHEK  =	$B4 

STATE   =	$B5 

MOVEN   =	$B6 

REV	=       $B7

OMOVE   =	$DC 

WCAP0   =	$DD 

COUNT   =	$DE 

BCAP2   =	$DE 

WCAP2   =	$DF 

BCAP1   =	$E0 

WCAP1   =	$E1 

BCAP0   =	$E2 

MOB     =	$E3 

MAXC    =	$E4 

CC      =	$E5 

PCAP    =	$E6 

BMOB    =	$E3 

BMAXC   =	$E4 

BMCC    =	$E5 		; was BCC (TASS doesn't like it as a label)

BMAXP   =	$E6 

XMAXC   =	$E8 

WMOB    =	$EB 

WMAXC   =	$EC 

WCC     =	$ED 

WMAXP   =	$EE 

PMOB    =	$EF 

PMAXC   =	$F0 

PCC     =	$F1 

PCP     =	$F2 

OLDKY   =	$F3 

BESTP   =	$FB 

BESTV   =	$FA 

BESTM   =	$F9 

DIS1    =	$FB 

DIS2    =	$FA 

DIS3    =	$F9 

temp    =       $FC

;

;

;

		*=$1000			; load into RAM @ $1000-$15FF


		LDA     #$00		; REVERSE TOGGLE

		STA     REV

                JSR     Init_6551

CHESS		CLD			; INITIALIZE

		LDX	#$FF		; TWO STACKS

		TXS	

		LDX	#$C8

		STX	SP2

;		

;       ROUTINES TO LIGHT LED

;       DISPLAY AND GET KEY

;       FROM KEYBOARD

;		

OUT		JSR	pout		; DISPLAY AND

		JSR	KIN		; GET INPUT   *** my routine waits for a keypress

;		CMP	OLDKY		; KEY IN ACC  *** no need to debounce

;		BEQ	OUT		; (DEBOUNCE)

;		STA	OLDKY

;		

		CMP	#$43		; [C]

		BNE	NOSET		; SET UP

		LDX	#$1F		; BOARD

WHSET		LDA	SETW,X		; FROM

		STA	BOARD,X		; SETW

		DEX	

		BPL	WHSET

		LDX	#$1B		; *ADDED

		STX	OMOVE		; INITS TO $FF

		LDA	#$CC		; Display CCC

		BNE	CLDSP

;		

NOSET		CMP	#$45		; [E]

		BNE	NOREV		; REVERSE

		JSR	REVERSE        	; BOARD IS

		SEC

		LDA	#$01

		SBC	REV

		STA	REV		; TOGGLE REV FLAG

		LDA	#$EE            ; IS

		BNE	CLDSP

;		

NOREV		CMP	#$40			; [P]

		BNE	NOGO           	; PLAY CHESS

		JSR	GO

CLDSP		STA	DIS1          	; DISPLAY

		STA	DIS2         	; ACROSS

		STA	DIS3          	; DISPLAY

		BNE	CHESS

;		

NOGO		CMP	#$0D            ; [Enter]

		BNE	NOMV          	; MOVE MAN

		JSR	MOVE          	; AS ENTERED

		JMP	DISP

NOMV		CMP     #$41		; [Q] ***Added to allow game exit***

		BEQ     DONE		; quit the game, exit back to system.  

		JMP	INPUT		; process move

DONE		JMP     $FF00		; *** MUST set this to YOUR OS starting address

;		

;       THE ROUTINE JANUS DIRECTS THE

;       ANALYSIS BY DETERMINING WHAT

;       SHOULD OCCUR AFTER EACH MOVE

;       GENERATED BY GNM

;		

;		

;

JANUS		LDX	STATE

		BMI	NOCOUNT

;		

;       THIS ROUTINE COUNTS OCCURRENCES

;       IT DEPENDS UPON STATE TO INDEX

;       THE CORRECT COUNTERS

;		

COUNTS		LDA	PIECE

		BEQ	OVER           	; IF STATE=8

		CPX 	#$08           	; DO NOT COUNT

		BNE	OVER          	; BLK MAX CAP

		CMP	BMAXP        	; MOVES FOR

		BEQ	XRT           	; WHITE

; 		

OVER		INC	MOB,X          	; MOBILITY

		CMP 	#$01           	;  + QUEEN

		BNE	NOQ           	; FOR TWO

		INC	MOB,X

;		

NOQ		BVC	NOCAP

		LDY	#$0F           	; CALCULATE

		LDA	SQUARE       	; POINTS

ELOOP		CMP	BK,Y           	; CAPTURED

		BEQ	FOUN          	; BY THIS

		DEY			; MOVE

		BPL	ELOOP

FOUN		LDA	POINTS,Y

		CMP	MAXC,X

		BCC	LESS          	; SAVE IF

		STY	PCAP,X         	; BEST THIS

		STA	MAXC,X         	; STATE

;		

LESS		CLC	

		PHP			; ADD TO

		ADC	CC,X           	; CAPTURE

		STA	CC,X           	; COUNTS

		PLP	

;		

NOCAP		CPX	#$04

		BEQ	ON4

		BMI	TREE          	;(=00 ONLY)

XRT		RTS	

;		

;      GENERATE FURTHER MOVES FOR COUNT

;      AND ANALYSIS	

;		

ON4		LDA	XMAXC        	; SAVE ACTUAL 

		STA	WCAP0         	; CAPTURE

		LDA	#$00           	; STATE=0

		STA	STATE

		JSR	MOVE          	; GENERATE

		JSR	REVERSE       	; IMMEDIATE

		JSR	GNMZ         	; REPLY MOVES  

		JSR	REVERSE

;		

		LDA	#$08       	; STATE=8

		STA	STATE        	; GENERATE

;		JSR	OHM          	; CONTINUATION

		JSR	UMOVE         	; MOVES

;		

		JMP	STRATGY       	; FINAL EVALUATION

NOCOUNT	CPX	#$F9

		BNE	TREE

;		

;      DETERMINE IF THE KING CAN BE

;      TAKEN, USED BY CHKCHK

;		

		LDA	BK           	; IS KING

		CMP	SQUARE       	; IN CHECK?

		BNE	RETJ          	; SET INCHEK=0

		LDA	#$00           	; IF IT IS

		STA	INCHEK

RETJ		RTS	

;		

;      IF A PIECE HAS BEEN CAPTURED BY

;      A TRIAL MOVE, GENERATE REPLIES &

;      EVALUATE THE EXCHANGE GAIN/LOSS

;		

TREE		BVC	RETJ          	; NO CAP

		LDY	#$07           	; (PIECES)

		LDA	SQUARE

LOOPX		CMP	BK,Y

		BEQ	FOUNX

		DEY	

		BEQ	RETJ          	; (KING)

		BPL	LOOPX         	; SAVE

FOUNX		LDA	POINTS,Y       	; BEST CAP

		CMP	BCAP0,X        	; AT THIS

		BCC	NOMAX         	; LEVEL

		STA	BCAP0,X

NOMAX		DEC	STATE

		LDA	#$FB           	; IF STATE=FB

		CMP	STATE        	; TIME TO TURN

		BEQ	UPTREE        	; AROUND

		JSR	GENRM         	; GENERATE FURTHER

UPTREE		INC	STATE        	; CAPTURES

		RTS	

;		

;      THE PLAYER'S MOVE IS INPUT

;		

INPUT		CMP	#$08           	; NOT A LEGAL

		BCS	ERROR      	; SQUARE #

		JSR	DISMV

DISP		LDX	#$1F

SEARCH		LDA	BOARD,X

		CMP	DIS2

		BEQ	HERE          	; DISPLAY

		DEX			; PIECE AT    

		BPL	SEARCH        	; FROM

HERE		STX	DIS1         	; SQUARE

		STX	PIECE

ERROR		JMP	CHESS

;		

;      GENERATE ALL MOVES FOR ONE

;      SIDE, CALL JANUS AFTER EACH

;      ONE FOR NEXT STE?

;		

;

<snip>

;

; end of file

It is scary that I can understand most of that without having touched it for 20 plus years.

#6
Guest_Kaabi_*

Guest_Kaabi_*
  • Guests
Is that some kind of chess program or something? I saw it mentioning a lot of things relating to chess so I assume it is.

#7
icepack

icepack

    Programmer

  • Members
  • PipPipPipPip
  • 115 posts
^ MicroChess © 1996-2002 Peter Jennings, peterj@benlo.com
first line

#8
Crane

Crane

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 398 posts
Wow, that is hard looking code Jonas! So that is what you use to do for a job?