Subject: Re: Native boot [was Booter 1.8]
To: The Great Mr. Kurtz <davagatw@mars.utm.edu>
From: Andrew Gillham <gillhaa@ghost.whirlpool.com>
List: port-mac68k
Date: 12/17/1995 20:44:26
> likely that my program's runtime module crashed.  Dunno.  If somebody has 
> a simple program to do something like scramble the video memory or 
> something else that doesn't use any MacOS code, could you drop me a 
> note.  I'd like to test this theory, but I don't have any kind of a 

Ok, I'm appending:
	'bootb' which is a 1024 byte bootblock
	bootblock.s the source. (written by Brad Pickering for MacMinix)
	macboot.c - does some scribbling on video memory. (on my IIci)

I've been doing something like:
	gcc -static -o macboot macboot.c
	cat bootb macboot > image
	dd if=image of=/dev/fd0a  (on my NetBSD/i386 machine)

You need to change the 0xfbb00020 value in macboot.c to the VIDEOADDR
value that Booter lists for your machine.  You should see some stuff
drawn on the screen right after the happy mac. Oh, and bootblock.s has
to be compiled on MacMinix, so I'm just using the binary.

The bootblock automatically skips the first 32 bytes (a.out header),
but I'm not 100% sure how much code it reads from the disk!  Could
somebody interpret the 'ioXXXX' calls?  It looks like 36 sectors, but...

-Andrew

--- cut here for bootb.uue ---
begin 644 bootb
M3$M@```(1`````0`(`YF(BQ(('D```$,2^C_X"/-```)!$_M_RXCSP``"0@R
M/``!8'!"IR\/J'2H?2!Y```!#$OH_^`CS0``"01/[?\N(\\```D(('D```*F
M(\@```*J(\@```$8T?P``R``(\@```$4H"TP/``4H&U!^@!:(\@```*Z(_P`
M<`!0```#^"/\`0`!$````_P_/``*,CD```(0("X`")_`*$]/[_^P/T$`%C]\
M__L`&"],`"`O0``D/WP``0`L+WP```0``"X@3Z`"3NP`(``"!-(`"@BN````
M```````(K@`*`!X`*$5R<F]R````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
B````````````````````````````````````````````````
`
end

--- cut here for bootblock.s ---

	.sect	.text
	.sect	.rom
	.sect	.data
	.sect	.bss

	.extern	_BufPtr
	.extern	_CurrentA5
	.extern _CurStackBase
	.extern	_SysZone
	.extern	_ApplZone
	.extern	_TheZone
	.extern	_HeapEnd
	.extern	_DSAlertTab
	.extern	_DSAlertRect
	.extern	_BootDrive

GetPort = 0xa874
ClosePort = 0xa87d
SetApplBase = 0xa057
SetApplLimit = 0xa02d
InitApplZone = 0xa02c
InitEvents = 0xa06d
Read = 0xa002

AppParamSize = 32	! according to IM V 2
QDSize = 210		! according to minix crtmac.s
PBSize = 80

HEAP_SIZE = 204800

ioCompletion = 12
ioVRefNum = 22
ioRefNum = 24
ioBuffer = 32
ioReqCount = 36
ioPosMode = 44
ioPosOffset = 46

	.sect	.text

	.data2	0x4c4b
	.data2	0x6000
	.data2	0x0008
	.data2	0x4400
	.data4	0x00000000
	move.l	a6,d0		! Check for fake boot (a6 == 0 means fake)
	bne	real

! Make a6 look real
	move.l	a0,a6
! Make Application Parameters
	move.l	_BufPtr,a0
	lea	-AppParamSize(a0),a5
	move.l	a5,_CurrentA5
! Make QuickDraw Globals
	lea	-QDSize(a5),a7
	move.l	a7,_CurStackBase
! Load MacBoot from drive 1
	move.w	#1,d1
	bra	load

! Close Current Port
real:	clr.l	-(a7)
	move.l	a7,-(a7)
	.data2	GetPort
	.data2	ClosePort
! Make Application Parameters
	move.l	_BufPtr,a0
	lea	-AppParamSize(a0),a5
	move.l	a5,_CurrentA5
! Make QuickDraw Globals
	lea	-QDSize(a5),a7
	move.l	a7,_CurStackBase
! Setup Zones
	move.l	_SysZone,a0
	move.l	a0,_ApplZone
	move.l	a0,_TheZone
	add.l	#HEAP_SIZE,a0
	move.l	a0,_HeapEnd
	.data2	SetApplLimit
! Init Events
	move.w	#20,d0
	.data2	InitEvents
! Setup System Error Handler
	lea	AlertTab,a0
	move.l	a0,_DSAlertTab
	move.l	#0x00700050,_DSAlertRect
	move.l	#0x01000110,_DSAlertRect+4
	move.w	#10,-(a7)
! Load MacBoot
	move.w	_BootDrive,d1
load:	move.l	8(a6),d0
	sub.l	d0,a7
	move.l	a7,a4
	lea	-PBSize(a7),a7
	move.w	d1,ioVRefNum(a7)
	move.w	#-5,ioRefNum(a7)
	move.l	a4,ioBuffer(a7)
	move.l	d0,ioReqCount(a7)
	move.w	#1,ioPosMode(a7)
	move.l	#1024,ioPosOffset(a7)
	move.l	a7,a0
	.data2	Read
	jmp	32(a4)

AlertTab:
	.data2	2		! item count
	.data2	1234		! alert id (err id)
	.data2	10		! item length
	.data2	2222		! text 1 id
	.data2	0		! text 2 id
	.data2	0		! icon id
	.data2	0		! proc id
	.data2	0		! button id
	.data2	2222		! text id
	.data2	10		! text item length
	.data2	30,40		! text location
	.data1	'E','r','r','o','r',0

--- cut here for macboot.c ---


main()
{
	int i;

	drawline(0x1e);
	drawline(0x1f);
	drawline(0x20);
	drawline(0x21);
	drawline(0x22);
	drawline(0x23);
	drawline(0x24);

	for (i=100; i<200; i++)
		putpixel(500, i);

	while(1);

}

drawline(int offset)
{
int j;
unsigned char *sc;
unsigned long i;

sc = (unsigned char *) 0xfbb00020;
sc += offset;
for(j = 0 ; j < 400; j++) 
	{
	*sc = (unsigned char)0xffff;
	sc += 1024;
	for (i=0 ; i <5000; i++);
	}
}

putpixel(int xx, int yy)
{
	unsigned char *sc;
	
	sc = (unsigned char *) 0xfbb00020;
	sc += yy * 1024 + xx;
	*sc = 0xff;
}

/* that's all the included files */