They're too generic to be kept in a target specific library and rather simple to be worth for an added library.
Code: Select all
/*=======================================================
Resets (clears) the bit 'bit' in the word pointed
to by 'word'.
No return value.
Bits are numbered 0 to 15, right to left.
*/
#include <sorcerer.h>
void clrbit(unsigned int *word, int bit)
{
*word=*word&(~(1<<bit));
}
Code: Select all
/*=======================================================
Sets the bit 'bit' in the word pointed to by
'word'.
No return value.
Bits are numbered 0 to 15, right to left.
*/
#include <sorcerer.h>
void setbit(unsigned int *word, int bit)
{
*word=*word|(1<<bit);
}
Code: Select all
/*=======================================================
Swaps the contents of the words pointed to by
p1 and p2.
ie: if w1=1234 and w2=5678 and p1 points to w1
and p2 points to w2, then after swap(p1,p2)
w1 will contain 5678 and w2 will contain 1234.
(See K & R, p117)
No return value.
*/
#include <sorcerer.h>
void swap(int *p1, int *p2)
{ int *temp;
*temp=*p1;
*p1=*p2;
*p2=*temp;
}
Code: Select all
;=============================================================
;
; int swaphl(int p1)
;
; Returns the 16 bit word P1 with HI and LO bytes swapped.
;
SECTION code_clib
PUBLIC swaphl
PUBLIC _swaphl
swaphl:
_swaphl:
LD d,h ;and swap it!
LD h,l
LD l,d
ret
'swapin()' was a function in BDS C to load a block of memory from disk.
Code: Select all
/*=======================================================
Undoes what swapin does:
ie swaps out to a filename pointed to by name
the contents of memory between saddr and eaddr
(inclusive).
Previous contents are discarded.
Returns either
0 if successful, or
-1 otherwise.
*/
#define __HAVESEED
#include <sorcerer.h>
#include <stdio.h>
#include <unistd.h>
int swapout(char *name, int saddr, int eaddr)
{ int nbl;
int fd;
// if ((fd=creat(name)) == -1) return fd;
if ((fd=fopen(filename,"wb"))==0) return fd;
nbl=eaddr-saddr+1;
// if (write(fd,saddr,nbl) != nbl) {
if (fwrite(saddr, 1, nbl, fd) != nbl) {
unlink(name);
return -1;
}
fclose(fd);
return 0;
}
Code: Select all
/*=======================================================
Returns:
1 if bit 'bit' is set in the word pointed to
by 'word', or
0 otherwise.
Bits are numbered 0 to 15, right to left.
*/
#include <sorcerer.h>
int tstbit(unsigned int *word, int bit)
{
if ((1<<bit)&*word)
return 1;
else
return 0;
}